﻿(function(a) {
    a.fn.extend({
        reflect: function(b) {
            b = a.extend({ height: 0.18, opacity: 0.25 }, b);
            return this.each(function() {
                var c = this;
                if (/^img$/i.test(c.tagName)) {

                    function d() {
                        var g = c.width, f = c.height, l, i, m, h, k;
                        i = Math.floor((b.height > 1) ? Math.min(f, b.height) : f * b.height);
                        if (a.browser.msie) {
                            l = a("<img />").attr("src", c.src).css({ width: g, height: f, marginBottom: i - f, filter: "flipv progid:DXImageTransform.Microsoft.Alpha(opacity=" + (b.opacity * 100) + ", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=" + (i / f * 100) + ")" })[0];
                        } else {
                            l = a("<canvas />")[0];
                            if (!l.getContext) {
                                return;
                            }
                            h = l.getContext("2d");
                            try {
                                a(l).attr({ width: g, height: i }).css('margin-left', '1px');
                                h.save();
                                h.translate(0, f - 1);
                                h.scale(1, -1);
                                h.drawImage(c, 0, 0, g, f);
                                h.restore();
                                h.globalCompositeOperation = "destination-out";
                                k = h.createLinearGradient(0, 0, 0, i);
                                k.addColorStop(0, "rgba(255, 255, 255, " + (1 - b.opacity) + ")");
                                k.addColorStop(1, "rgba(255, 255, 255, 1.0)");
                                h.fillStyle = k;
                                h.rect(0, 0, g, i);
                                h.fill();
                            } catch(j) {
                                return;
                            }
                        }
                        a(l).css({ display: "block", border: 0 });
                        if (c.parentNode.tagName.match(/^div$/i)) {
                            m = a(c.parentNode).html([c, l])[0];
                        } else {
                            m = a(/^a$/i.test(c.parentNode.tagName) ? "<span />" : "<div />").insertAfter(c).append([c, l])[0];
                            m.className = c.className;
                            a.data(c, "reflected", m.style.cssText = c.style.cssText);
                        }
                        a(m).css({ height: f + i, overflow: "hidden" });
                        c.style.cssText = "display: block;";
                        c.className = "reflected";
                    }

                    if (c.complete) {
                        d();
                    } else {
                        a(c).load(d);
                    }
                }
            });
        }
    });
})(jQuery);

(function(c) {
    var a = ["DOMMouseScroll", "mousewheel"];
    c.event.special.mousewheel = {
        setup: function() {
            if (this.addEventListener) {
                for (var d = a.length; d;) {
                    this.addEventListener(a[--d], b, false);
                }
            } else {
                this.onmousewheel = b;
            }
        },
        teardown: function() {
            if (this.removeEventListener) {
                for (var d = a.length; d;) {
                    this.removeEventListener(a[--d], b, false);
                }
            } else {
                this.onmousewheel = null;
            }
        }
    };
    c.fn.extend({ mousewheel: function(d) { return d ? this.bind("mousewheel", d) : this.trigger("mousewheel"); }, unmousewheel: function(d) { return this.unbind("mousewheel", d); } });

    function b(i) {
        var g = i || window.event, f = [].slice.call(arguments, 1), j = 0, h = true, e = 0, d = 0;
        i = c.event.fix(g);
        i.type = "mousewheel";
        if (i.wheelDelta) {
            j = i.wheelDelta / 120;
        }
        if (i.detail) {
            j = -i.detail / 3;
        }
        d = j;
        if (g.axis !== undefined && g.axis === g.HORIZONTAL_AXIS) {
            d = 0;
            e = -1 * j;
        }
        if (g.wheelDeltaY !== undefined) {
            d = g.wheelDeltaY / 120;
        }
        if (g.wheelDeltaX !== undefined) {
            e = -1 * g.wheelDeltaX / 120;
        }
        f.unshift(i, j, e, d);
        return c.event.handle.apply(this, f);
    }
})(jQuery);

(function(b, a, c) {
    b.fn.jScrollPane = function(f) {

        function d(C, L) {
            var au, N = this, V, ah, v, aj, Q, W, y, q, av, aB, ap, i, H, h, j, X, R, al, U, t, A, am, ac, ak, F, l, ao, at, x, aq, aE, g, aA, ag = true, M = true, aD = false, k = false, Z = b.fn.mwheelIntent ? "mwheelIntent.jsp" : "mousewheel.jsp";
            aE = C.css("paddingTop") + " " + C.css("paddingRight") + " " + C.css("paddingBottom") + " " + C.css("paddingLeft");
            g = (parseInt(C.css("paddingLeft")) || 0) + (parseInt(C.css("paddingRight")) || 0);
            an(L);

            function an(aH) {
                var aL, aK, aJ, aG, aF, aI;
                au = aH;
                if (V == c) {
                    C.css({ overflow: "hidden", padding: 0 });
                    ah = C.innerWidth() + g;
                    v = C.innerHeight();
                    C.width(ah);
                    V = b('<div class="jspPane" />').wrap(b('<div class="jspContainer" />').css({ width: ah + "px", height: v + "px" }));
                    C.wrapInner(V.parent());
                    aj = C.find(">.jspContainer");
                    V = aj.find(">.jspPane");
                    V.css("padding", aE);
                } else {
                    C.css("width", null);
                    aI = C.outerWidth() + g != ah || C.outerHeight() != v;
                    if (aI) {
                        ah = C.innerWidth() + g;
                        v = C.innerHeight();
                        aj.css({ width: ah + "px", height: v + "px" });
                    }
                    aA = V.innerWidth();
                    if (!aI && V.outerWidth() == Q && V.outerHeight() == W) {
                        if (aB || av) {
                            V.css("width", aA + "px");
                            C.css("width", (aA + g) + "px");
                        }
                        return;
                    }
                    V.css("width", null);
                    C.css("width", (ah) + "px");
                    aj.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end();
                }
                aL = V.clone().css("position", "absolute");
                aK = b('<div style="width:1px; position: relative;" />').append(aL);
                b("body").append(aK);
                Q = Math.max(V.outerWidth(), aL.outerWidth());
                aK.remove();
                W = V.outerHeight();
                y = Q / ah;
                q = W / v;
                av = q > 1;
                aB = y > 1;
                if (!(aB || av)) {
                    C.removeClass("jspScrollable");
                    V.css({ top: 0, width: aj.width() - g });
                    n();
                    D();
                    O();
                    w();
                    af();
                } else {
                    C.addClass("jspScrollable");
                    aJ = au.maintainPosition && (H || X);
                    if (aJ) {
                        aG = ay();
                        aF = aw();
                    }
                    aC();
                    z();
                    E();
                    if (aJ) {
                        K(aG);
                        J(aF);
                    }
                    I();
                    ad();
                    if (au.enableKeyboardNavigation) {
                        P();
                    } else {
                        C.css("outline", "none");
                        if ("hideFocus" in aj[0]) {
                            C.attr("hideFocus", true);
                        }
                    }
                    if (au.clickOnTrack) {
                        p();
                    }
                    B();
                    if (au.hijackInternalLinks) {
                        m();
                    }
                }
                if (au.autoReinitialise && !aq) {
                    aq = setInterval(function() { an(au); }, au.autoReinitialiseDelay);
                } else {
                    if (!au.autoReinitialise && aq) {
                        clearInterval(aq);
                    }
                }
                C.trigger("jsp-initialised", [aB || av]);
            }

            function aC() {
                if (av) {
                    aj.append(b('<div class="jspVerticalBar" />').append(b('<div class="jspCap jspCapTop" />'), b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragTop" />'), b('<div class="jspDragBottom" />'))), b('<div class="jspCap jspCapBottom" />')));
                    R = aj.find(">.jspVerticalBar");
                    al = R.find(">.jspTrack");
                    ap = al.find(">.jspDrag");
                    if (au.showArrows) {
                        am = b('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp", az(0, -1)).bind("click.jsp", ax);
                        ac = b('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp", az(0, 1)).bind("click.jsp", ax);
                        if (au.arrowScrollOnHover) {
                            am.bind("mouseover.jsp", az(0, -1, am));
                            ac.bind("mouseover.jsp", az(0, 1, ac));
                        }
                        ai(al, au.verticalArrowPositions, am, ac);
                    }
                    t = v;
                    aj.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function() { t -= b(this).outerHeight(); });
                    ap.hover(function() { ap.addClass("jspHover"); }, function() { ap.removeClass("jspHover"); }).bind("mousedown.jsp", function(aF) {
                        b("html").bind("dragstart.jsp selectstart.jsp", function() { return false; });
                        ap.addClass("jspActive");
                        var s = aF.pageY - ap.position().top;
                        b("html").bind("mousemove.jsp", function(aG) { S(aG.pageY - s, false); }).bind("mouseup.jsp mouseleave.jsp", ar);
                        return false;
                    });
                    o();
                }
            }

            function o() {
                al.height(t + "px");
                H = 0;
                U = au.verticalGutter + al.outerWidth();
                if (!au.fixedPane) {
                    V.width(ah - U - g);
                } else {
                    V.width(ah - g);
                }
                if (R.position().left == 0) {
                    V.css("margin-left", U + "px");
                }
            }

            function z() {
                if (aB) {
                    aj.append(b('<div class="jspHorizontalBar" />').append(b('<div class="jspCap jspCapLeft" />'), b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragLeft" />'), b('<div class="jspDragRight" />'))), b('<div class="jspCap jspCapRight" />')));
                    ak = aj.find(">.jspHorizontalBar");
                    F = ak.find(">.jspTrack");
                    h = F.find(">.jspDrag");
                    if (au.showArrows) {
                        at = b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp", az(-1, 0)).bind("click.jsp", ax);
                        x = b('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp", az(1, 0)).bind("click.jsp", ax);
                        if (au.arrowScrollOnHover) {
                            at.bind("mouseover.jsp", az(-1, 0, at));
                            x.bind("mouseover.jsp", az(1, 0, x));
                        }
                        ai(F, au.horizontalArrowPositions, at, x);
                    }
                    h.hover(function() { h.addClass("jspHover"); }, function() { h.removeClass("jspHover"); }).bind("mousedown.jsp", function(aF) {
                        b("html").bind("dragstart.jsp selectstart.jsp", function() { return false; });
                        h.addClass("jspActive");
                        var s = aF.pageX - h.position().left;
                        b("html").bind("mousemove.jsp", function(aG) { T(aG.pageX - s, false); }).bind("mouseup.jsp mouseleave.jsp", ar);
                        return false;
                    });
                    l = aj.innerWidth();
                    ae();
                } else {
                }
            }

            function ae() {
                aj.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function() { l -= b(this).outerWidth(); });
                F.width(l + "px");
                X = 0;
            }

            function E() {
                if (aB && av) {
                    var aF = F.outerHeight(), s = al.outerWidth();
                    t -= aF;
                    b(ak).find(">.jspCap:visible,>.jspArrow").each(function() { l += b(this).outerWidth(); });
                    l -= s;
                    v -= s;
                    ah -= aF;
                    F.parent().append(b('<div class="jspCorner" />').css("width", aF + "px"));
                    o();
                    ae();
                }
                if (aB) {
                    V.width((aj.outerWidth() - g) + "px");
                }
                W = V.outerHeight();
                q = W / v;
                if (aB) {
                    ao = 1 / y * l;
                    if (ao > au.horizontalDragMaxWidth) {
                        ao = au.horizontalDragMaxWidth;
                    } else {
                        if (ao < au.horizontalDragMinWidth) {
                            ao = au.horizontalDragMinWidth;
                        }
                    }
                    h.width(ao + "px");
                    j = l - ao;
                    ab(X);
                }
                if (av) {
                    A = 1 / q * t;
                    if (A > au.verticalDragMaxHeight) {
                        A = au.verticalDragMaxHeight;
                    } else {
                        if (A < au.verticalDragMinHeight) {
                            A = au.verticalDragMinHeight;
                        }
                    }
                    ap.height(A + "px");
                    i = t - A;
                    aa(H);
                }
            }

            function ai(aG, aI, aF, s) {
                var aK = "before", aH = "after", aJ;
                if (aI == "os") {
                    aI = /Mac/.test(navigator.platform) ? "after" : "split";
                }
                if (aI == aK) {
                    aH = aI;
                } else {
                    if (aI == aH) {
                        aK = aI;
                        aJ = aF;
                        aF = s;
                        s = aJ;
                    }
                }
                aG[aK](aF)[aH](s);
            }

            function az(aF, s, aG) {
                return function() {
                    G(aF, s, this, aG);
                    this.blur();
                    return false;
                };
            }

            function G(aH, aF, aK, aJ) {
                aK = b(aK).addClass("jspActive");
                var aI, s = function() {
                    if (aH != 0) {
                        T(X + aH * au.arrowButtonSpeed, false);
                    }
                    if (aF != 0) {
                        S(H + aF * au.arrowButtonSpeed, false);
                    }
                }, aG = setInterval(s, au.arrowRepeatFreq);
                s();
                aI = aJ == c ? "mouseup.jsp" : "mouseout.jsp";
                aJ = aJ || b("html");
                aJ.bind(aI, function() {
                    aK.removeClass("jspActive");
                    clearInterval(aG);
                    aJ.unbind(aI);
                });
            }

            function p() {
                w();
                if (av) {
                    al.bind("mousedown.jsp", function(aH) {
                        if (aH.originalTarget == c || aH.originalTarget == aH.currentTarget) {
                            var aG = b(this), s = setInterval(function() {
                                var aI = aG.offset(), aJ = aH.pageY - aI.top;
                                if (H + A < aJ) {
                                    S(H + au.trackClickSpeed);
                                } else {
                                    if (aJ < H) {
                                        S(H - au.trackClickSpeed);
                                    } else {
                                        aF();
                                    }
                                }
                            }, au.trackClickRepeatFreq), aF = function() {
                                s && clearInterval(s);
                                s = null;
                                b(document).unbind("mouseup.jsp", aF);
                            };
                            b(document).bind("mouseup.jsp", aF);
                            return false;
                        }
                    });
                }
                if (aB) {
                    F.bind("mousedown.jsp", function(aH) {
                        if (aH.originalTarget == c || aH.originalTarget == aH.currentTarget) {
                            var aG = b(this), s = setInterval(function() {
                                var aI = aG.offset(), aJ = aH.pageX - aI.left;
                                if (X + ao < aJ) {
                                    T(X + au.trackClickSpeed);
                                } else {
                                    if (aJ < X) {
                                        T(X - au.trackClickSpeed);
                                    } else {
                                        aF();
                                    }
                                }
                            }, au.trackClickRepeatFreq), aF = function() {
                                s && clearInterval(s);
                                s = null;
                                b(document).unbind("mouseup.jsp", aF);
                            };
                            b(document).bind("mouseup.jsp", aF);
                            return false;
                        }
                    });
                }
            }

            function w() {
                F && F.unbind("mousedown.jsp");
                al && al.unbind("mousedown.jsp");
            }

            function ar() {
                b("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");
                ap && ap.removeClass("jspActive");
                h && h.removeClass("jspActive");
            }

            function S(s, aF) {
                if (!av) {
                    return;
                }
                if (s < 0) {
                    s = 0;
                } else {
                    if (s > i) {
                        s = i;
                    }
                }
                if (aF == c) {
                    aF = au.animateScroll;
                }
                if (aF) {
                    N.animate(ap, "top", s, aa);
                } else {
                    ap.css("top", s);
                    aa(s);
                }
            }

            function aa(aF) {
                if (aF == c) {
                    aF = ap.position().top;
                }
                aj.scrollTop(0);
                H = aF;
                var aI = H == 0, aG = H == i, aH = aF / i, s = -aH * (W - v);
                if (ag != aI || aD != aG) {
                    ag = aI;
                    aD = aG;
                    C.trigger("jsp-arrow-change", [ag, aD, M, k]);
                }
                u(aI, aG);
                V.css("top", s);
                C.trigger("jsp-scroll-y", [-s, aI, aG]);
            }

            function T(aF, s) {
                if (!aB) {
                    return;
                }
                if (aF < 0) {
                    aF = 0;
                } else {
                    if (aF > j) {
                        aF = j;
                    }
                }
                if (s == c) {
                    s = au.animateScroll;
                }
                if (s) {
                    N.animate(h, "left", aF, ab);
                } else {
                    h.css("left", aF);
                    ab(aF);
                }
            }

            function ab(aF) {
                if (aF == c) {
                    aF = h.position().left;
                }
                aj.scrollTop(0);
                X = aF;
                var aI = X == 0, aH = X == j, aG = aF / j, s = -aG * (Q - ah);
                if (M != aI || k != aH) {
                    M = aI;
                    k = aH;
                    C.trigger("jsp-arrow-change", [ag, aD, M, k]);
                }
                r(aI, aH);
                V.css("left", s);
                C.trigger("jsp-scroll-x", [-s, aI, aH]);
            }

            function u(aF, s) {
                if (au.showArrows) {
                    am[aF ? "addClass" : "removeClass"]("jspDisabled");
                    ac[s ? "addClass" : "removeClass"]("jspDisabled");
                }
                au.onScroll();
            }

            function r(aF, s) {
                if (au.showArrows) {
                    at[aF ? "addClass" : "removeClass"]("jspDisabled");
                    x[s ? "addClass" : "removeClass"]("jspDisabled");
                }
                au.onScroll();
            }

            function J(s, aF) {
                var aG = s / (W - v);
                S(aG * i, aF);
            }

            function K(aF, s) {
                var aG = aF / (Q - ah);
                T(aG * j, s);
            }

            function Y(aN, aL, aF) {
                var aJ, aH, s = 0, aG, aK, aM;
                try {
                    aJ = b(aN);
                } catch(aI) {
                    return;
                }
                aH = aJ.outerHeight();
                aj.scrollTop(0);
                while (!aJ.is(".jspPane")) {
                    s += aJ.position().top;
                    aJ = aJ.offsetParent();
                    if (/^body|html$/i.test(aJ[0].nodeName)) {
                        return;
                    }
                }
                aG = aw();
                aK = aG + v;
                if (s < aG || aL) {
                    aM = s - au.verticalGutter;
                } else {
                    if (s + aH > aK) {
                        aM = s - v + aH + au.verticalGutter;
                    }
                }
                if (aM) {
                    J(aM, aF);
                }
            }

            function ay() { return -V.position().left; }

            function aw() { return -V.position().top; }

            function ad() {
                aj.unbind(Z).bind(Z, function(aI, aJ, aH, aF) {
                    var aG = X, s = H;
                    T(X + aH * au.mouseWheelSpeed, false);
                    S(H - aF * au.mouseWheelSpeed, false);
                    return aG == X && s == H;
                });
            }

            function n() { aj.unbind(Z); }

            function ax() { return false; }

            function I() {
                V.unbind("focusin.jsp").bind("focusin.jsp", function(s) {
                    if (s.target === V[0]) {
                        return;
                    }
                    Y(s.target, false);
                });
            }

            function D() { V.unbind("focusin.jsp"); }

            function P() {
                var aF, s;
                C.attr("tabindex", 0).unbind("keydown.jsp").bind("keydown.jsp", function(aJ) {
                    if (aJ.target !== C[0]) {
                        return;
                    }
                    var aH = X, aG = H, aI = aF ? 6 : 16;
                    switch (aJ.keyCode) {
                    case 40:
                        S(H + aI, false);
                        break;
                    case 38:
                        S(H - aI, false);
                        break;
                    case 34:
                    case 32:
                        J(aw() + Math.max(32, v) - 16);
                        break;
                    case 33:
                        J(aw() - v + 16);
                        break;
                    case 35:
                        J(W - v);
                        break;
                    case 36:
                        J(0);
                        break;
                    case 39:
                        T(X + aI, false);
                        break;
                    case 37:
                        T(X - aI, false);
                        break;
                    }
                    if (!(aH == X && aG == H)) {
                        aF = true;
                        clearTimeout(s);
                        s = setTimeout(function() { aF = false; }, 260);
                        return false;
                    }
                });
            }

            function O() { C.attr("tabindex", "-1").removeAttr("tabindex").unbind("keydown.jsp"); }

            function B() {
                if (location.hash && location.hash.length > 1) {
                    var aG, aF;
                    try {
                        aG = b(location.hash);
                    } catch(s) {
                        return;
                    }
                    if (aG.length && V.find(aG)) {
                        if (aj.scrollTop() == 0) {
                            aF = setInterval(function() {
                                if (aj.scrollTop() > 0) {
                                    Y(location.hash, true);
                                    b(document).scrollTop(aj.position().top);
                                    clearInterval(aF);
                                }
                            }, 50);
                        } else {
                            Y(location.hash, true);
                            b(document).scrollTop(aj.position().top);
                        }
                    }
                }
            }

            function af() { b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack"); }

            function m() {
                af();
                b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack", function() {
                    var s = this.href.split("#"), aF;
                    if (s.length > 1) {
                        aF = s[1];
                        if (aF.length > 0 && V.find("#" + aF).length > 0) {
                            Y("#" + aF, true);
                            return false;
                        }
                    }
                });
            }

            b.extend(N, {
                reinitialise: function(aF) {
                    aF = b.extend({}, aF, au);
                    an(aF);
                },
                scrollToElement: function(aG, aF, s) { Y(aG, aF, s); },
                scrollTo: function(aG, s, aF) {
                    K(aG, aF);
                    J(s, aF);
                },
                scrollToX: function(aF, s) { K(aF, s); },
                scrollToY: function(s, aF) { J(s, aF); },
                scrollBy: function(aF, s, aG) {
                    N.scrollByX(aF, aG);
                    N.scrollByY(s, aG);
                },
                scrollByX: function(s, aG) {
                    var aF = ay() + s, aH = aF / (Q - ah);
                    T(aH * j, aG);
                },
                scrollByY: function(s, aG) {
                    var aF = aw() + s, aH = aF / (W - v);
                    S(aH * i, aG);
                },
                animate: function(aF, aI, s, aH) {
                    var aG = {};
                    aG[aI] = s;
                    aF.animate(aG, { duration: au.animateDuration, ease: au.animateEase, queue: false, step: aH });
                },
                getContentPositionX: function() { return ay(); },
                getContentPositionY: function() { return aw(); },
                getIsScrollableH: function() { return aB; },
                getIsScrollableV: function() { return av; },
                getContentPane: function() { return V; },
                scrollToBottom: function(s) { S(i, s); },
                hijackInternalLinks: function() { m(); }
            });
        }

        f = b.extend({}, b.fn.jScrollPane.defaults, f);
        var e;
        this.each(function() {
            var g = b(this), h = g.data("jsp");
            if (h) {
                h.reinitialise(f);
            } else {
                h = new d(g, f);
                g.data("jsp", h);
            }
            e = e ? e.add(g) : g;
        });
        return e;
    };
    b.fn.jScrollPane.defaults = {
        fixedPane: true, showArrows: false, maintainPosition: true, clickOnTrack: true, autoReinitialise: false, autoReinitialiseDelay: 500, verticalDragMinHeight: 20, verticalDragMaxHeight: 99999, horizontalDragMinWidth: 0, horizontalDragMaxWidth: 99999, animateScroll: false, animateDuration: 300, animateEase: "linear", hijackInternalLinks: false, verticalGutter: 4, horizontalGutter: 4, mouseWheelSpeed: 5, arrowButtonSpeed: 10, arrowRepeatFreq: 100, arrowScrollOnHover: false, trackClickSpeed: 30, trackClickRepeatFreq: 100, verticalArrowPositions: "split", horizontalArrowPositions: "split", enableKeyboardNavigation: false, hideFocus: true,
        onScroll: function() {
        }
    };
})(jQuery, this);

(function($, e, b) {
    var c = "hashchange", h = document, f, g = $.event.special, i = h.documentMode, d = "on" + c in e && (i === b || i > 7);

    function a(j) {
        j = j || location.href;
        return "#" + j.replace(/^[^#]*#?(.*)$/, "$1");
    }

    $.fn[c] = function(j) { return j ? this.bind(c, j) : this.trigger(c); };
    $.fn[c].delay = 50;
    g[c] = $.extend(g[c], {
        setup: function() {
            if (d) {
                return false;
            }
            $(f.start);
        },
        teardown: function() {
            if (d) {
                return false;
            }
            $(f.stop);
        }
    });
    f = (function() {
        var j = {}, p, m = a(), k = function(q) { return q; }, l = k, o = k;
        j.start = function() { p || n(); };
        j.stop = function() {
            p && clearTimeout(p);
            p = b;
        };

        function n() {
            var r = a(), q = o(m);
            if (r !== m) {
                l(m = r, q);
                $(e).trigger(c);
            } else {
                if (q !== m) {
                    location.href = location.href.replace(/#.*/, "") + q;
                }
            }
            p = setTimeout(n, $.fn[c].delay);
        }

        $.browser.msie && !d && (function() {
            var q, r;
            j.start = function() {
                if (!q) {
                    r = $.fn[c].src;
                    r = r && r + a();
                    q = $('<iframe tabindex="-1" title="empty"/>').hide().one("load", function() {
                        r || l(a());
                        n();
                    }).attr("src", r || "javascript:0").insertAfter("body")[0].contentWindow;
                    h.onpropertychange = function() {
                        try {
                            if (event.propertyName === "title") {
                                q.document.title = h.title;
                            }
                        } catch(s) {
                        }
                    };
                }
            };
            j.stop = k;
            o = function() { return a(q.location.href); };
            l = function(v, s) {
                var u = q.document, t = $.fn[c].domain;
                if (v !== s) {
                    u.title = h.title;
                    u.open();
                    t && u.write('<script>document.domain="' + t + '"<\/script>');
                    u.close();
                    q.location.hash = v;
                }
            };
        })();
        return j;
    })();
})(jQuery, this);

(function(c) {
    c.address = function() {
        var v = function(a) {
            c(c.address).trigger(c.extend(c.Event(a), function() {
                for (var b = {}, e = c.address.parameterNames(), f = 0, p = e.length; f < p; f++) b[e[f]] = c.address.parameter(e[f]);
                return { value: c.address.value(), path: c.address.path(), pathNames: c.address.pathNames(), parameterNames: e, parameters: b, queryString: c.address.queryString() };
            }.call(c.address)));
        }, w = function() {
            c().bind.apply(c(c.address), Array.prototype.slice.call(arguments));
            return c.address;
        }, r = function() {
            return M.pushState &&
                d.state !== k;
        }, s = function() { return ("/" + g.pathname.replace(new RegExp(d.state), "") + g.search + (D() ? "#" + D() : "")).replace(U, "/"); }, D = function() {
            var a = g.href.indexOf("#");
            return a != -1 ? B(g.href.substr(a + 1), l) : "";
        }, u = function() { return r() ? s() : D(); }, ha = function() { return "javascript"; }, N = function(a) {
            a = a.toString();
            return (d.strict && a.substr(0, 1) != "/" ? "/" : "") + a;
        }, B = function(a, b) {
            if (d.crawlable && b) return (a !== "" ? "!" : "") + a;
            return a.replace(/^\!/, "");
        }, x = function(a, b) { return parseInt(a.css(b), 10); }, V = function(a) {
            for (var b,
                e, f = 0, p = a.childNodes.length; f < p; f++) {
                try {
                    if ("src" in a.childNodes[f] && a.childNodes[f].src) b = String(a.childNodes[f].src);
                } catch(J) {
                }
                if (e = V(a.childNodes[f])) b = e;
            }
            return b;
        }, F = function() {
            if (!K) {
                var a = u();
                if (h != a)
                    if (y && q < 7) g.reload();
                    else {
                        y && q < 8 && d.history && t(O, 50);
                        h = a;
                        E(l);
                    }
            }
        }, E = function(a) {
            v(W);
            v(a ? X : Y);
            t(Z, 10);
        }, Z = function() {
            if (d.tracker !== "null" && d.tracker !== null) {
                var a = c.isFunction(d.tracker) ? d.tracker : j[d.tracker], b = (g.pathname + g.search + (c.address && !r() ? c.address.value() : "")).replace(/\/\//, "/").replace(/^\/$/,
                    "");
                if (c.isFunction(a)) a(b);
                else if (c.isFunction(j.urchinTracker)) j.urchinTracker(b);
                else if (j.pageTracker !== k && c.isFunction(j.pageTracker._trackPageview)) j.pageTracker._trackPageview(b);
                else j._gaq !== k && c.isFunction(j._gaq.push) && j._gaq.push(["_trackPageview", decodeURI(b)]);
            }
        }, O = function() {
            var a = ha() + ":" + l + ";document.open();document.writeln('<html><head><title>" + n.title.replace("'", "\\'") + "</title><script>var " + C + ' = "' + encodeURIComponent(u()) + (n.domain != g.hostname ? '";document.domain="' + n.domain :
                "") + "\";<\/script></head></html>');document.close();";
            if (q < 7) m.src = a;
            else m.contentWindow.location.replace(a);
        }, aa = function() {
            if (G && $ != -1) {
                var a, b = G.substr($ + 1).split("&");
                for (i = 0; i < b.length; i++) {
                    a = b[i].split("=");
                    if (/^(autoUpdate|crawlable|history|strict|wrap)$/.test(a[0])) d[a[0]] = isNaN(a[1]) ? /^(true|yes)$/i.test(a[1]) : parseInt(a[1], 10) !== 0;
                    if (/^(state|tracker)$/.test(a[0])) d[a[0]] = a[1];
                }
                G = null;
            }
            h = u();
        }, ca = function() {
            if (!ba) {
                ba = o;
                aa();
                var a = function() {
                    ia.call(this);
                    ja.call(this);
                }, b = c("body").ajaxComplete(a);
                a();
                if (d.wrap) {
                    c("body > *").wrapAll('<div style="padding:' + (x(b, "marginTop") + x(b, "paddingTop")) + "px " + (x(b, "marginRight") + x(b, "paddingRight")) + "px " + (x(b, "marginBottom") + x(b, "paddingBottom")) + "px " + (x(b, "marginLeft") + x(b, "paddingLeft")) + 'px;" />').parent().wrap('<div id="' + C + '" style="height:100%;overflow:auto;position:relative;' + (H && !window.statusbar.visible ? "resize:both;" : "") + '" />');
                    c("html, body").css({ height: "100%", margin: 0, padding: 0, overflow: "hidden" });
                    H && c('<style type="text/css" />').appendTo("head").text("#" +
                        C + "::-webkit-resizer { background-color: #fff; }");
                }
                if (y && q < 8) {
                    a = n.getElementsByTagName("frameset")[0];
                    m = n.createElement((a ? "" : "i") + "frame");
                    if (a) {
                        a.insertAdjacentElement("beforeEnd", m);
                        a[a.cols ? "cols" : "rows"] += ",0";
                        m.noResize = o;
                        m.frameBorder = m.frameSpacing = 0;
                    } else {
                        m.style.display = "none";
                        m.style.width = m.style.height = 0;
                        m.tabIndex = -1;
                        n.body.insertAdjacentElement("afterBegin", m);
                    }
                    t(function() {
                        c(m).bind("load", function() {
                            var e = m.contentWindow;
                            h = e[C] !== k ? e[C] : "";
                            if (h != u()) {
                                E(l);
                                g.hash = B(h, o);
                            }
                        });
                        m.contentWindow[C] ===
                            k && O();
                    }, 50);
                }
                t(function() {
                    v("init");
                    E(l);
                }, 1);
                if (!r())
                    if (y && q > 7 || !y && "on" + I in j)
                        if (j.addEventListener) j.addEventListener(I, F, l);
                        else j.attachEvent && j.attachEvent("on" + I, F);
                    else ka(F, 50);
            }
        }, ia = function() {
            var a, b = c("a"), e = b.size(), f = -1, p = function() {
                if (++f != e) {
                    a = c(b.get(f));
                    a.is('[rel*="address:"]') && a.address();
                    t(p, 1);
                }
            };
            t(p, 1);
        }, la = function() {
            if (h != u()) {
                h = u();
                E(l);
            }
        }, ma = function() {
            if (j.removeEventListener) j.removeEventListener(I, F, l);
            else j.detachEvent && j.detachEvent("on" + I, F);
        }, ja = function() {
            if (d.crawlable) {
                var a =
                    g.pathname.replace(/\/$/, "");
                c("body").html().indexOf("_escaped_fragment_") != -1 && c('a[href]:not([href^=http]), a[href*="' + document.domain + '"]').each(function() {
                    var b = c(this).attr("href").replace(/^http:/, "").replace(new RegExp(a + "/?$"), "");
                    if (b === "" || b.indexOf("_escaped_fragment_") != -1) c(this).attr("href", "#" + b.replace(/\/(.*)\?_escaped_fragment_=(.*)$/, "!$2"));
                });
            }
        }, k, C = "jQueryAddress", I = "hashchange", W = "change", X = "internalChange", Y = "externalChange", o = true, l = false, d = {
            autoUpdate: o,
            crawlable: l,
            history: o,
            strict: o,
            wrap: l
        }, z = c.browser, q = parseFloat(c.browser.version), da = z.mozilla, y = z.msie, ea = z.opera, H = z.webkit || z.safari, P = l, j = function() {
            try {
                return top.document !== k ? top : window;
            } catch(a) {
                return window;
            }
        }(), n = j.document, M = j.history, g = j.location, ka = setInterval, t = setTimeout, U = /\/{2,9}/g;
        z = navigator.userAgent;
        var m, G = V(document), $ = G ? G.indexOf("?") : -1, Q = n.title, K = l, ba = l, R = o, fa = o, L = l, h = u();
        if (y) {
            q = parseFloat(z.substr(z.indexOf("MSIE") + 4));
            if (n.documentMode && n.documentMode != q) q = n.documentMode != 8 ? 7 : 8;
            var ga = n.onpropertychange;
            n.onpropertychange = function() {
                ga && ga.call(n);
                if (n.title != Q && n.title.indexOf("#" + u()) != -1) n.title = Q;
            };
        }
        if (P = da && q >= 1 || y && q >= 6 || ea && q >= 9.5 || H && q >= 523) {
            if (ea) history.navigationMode = "compatible";
            if (document.readyState == "complete")
                var na = setInterval(function() {
                    if (c.address) {
                        ca();
                        clearInterval(na);
                    }
                }, 50);
            else {
                aa();
                c(ca);
            }
            c(window).bind("popstate", la).bind("unload", ma);
        } else !P && D() !== "" ? g.replace(g.href.substr(0, g.href.indexOf("#"))) : Z();
        return {
            bind: function(a, b, e) { return w(a, b, e); },
            init: function(a) {
                return w("init",
                    a);
            },
            change: function(a) { return w(W, a); },
            internalChange: function(a) { return w(X, a); },
            externalChange: function(a) { return w(Y, a); },
            baseURL: function() {
                var a = g.href;
                if (a.indexOf("#") != -1) a = a.substr(0, a.indexOf("#"));
                if (/\/$/.test(a)) a = a.substr(0, a.length - 1);
                return a;
            },
            autoUpdate: function(a) {
                if (a !== k) {
                    d.autoUpdate = a;
                    return this;
                }
                return d.autoUpdate;
            },
            crawlable: function(a) {
                if (a !== k) {
                    d.crawlable = a;
                    return this;
                }
                return d.crawlable;
            },
            history: function(a) {
                if (a !== k) {
                    d.history = a;
                    return this;
                }
                return d.history;
            },
            state: function(a) {
                if (a !==
                    k) {
                    d.state = a;
                    var b = s();
                    if (d.state !== k)
                        if (M.pushState) b.substr(0, 3) == "/#/" && g.replace(d.state.replace(/^\/$/, "") + b.substr(2));
                        else b != "/" && b.replace(/^\/#/, "") != D() && t(function() { g.replace(d.state.replace(/^\/$/, "") + "/#" + b); }, 1);
                    return this;
                }
                return d.state;
            },
            strict: function(a) {
                if (a !== k) {
                    d.strict = a;
                    return this;
                }
                return d.strict;
            },
            tracker: function(a) {
                if (a !== k) {
                    d.tracker = a;
                    return this;
                }
                return d.tracker;
            },
            wrap: function(a) {
                if (a !== k) {
                    d.wrap = a;
                    return this;
                }
                return d.wrap;
            },
            update: function() {
                L = o;
                this.value(h);
                L = l;
                return this;
            },
            title: function(a) {
                if (a !== k) {
                    t(function() {
                        Q = n.title = a;
                        if (fa && m && m.contentWindow && m.contentWindow.document) {
                            m.contentWindow.document.title = a;
                            fa = l;
                        }
                        if (!R && da) g.replace(g.href.indexOf("#") != -1 ? g.href : g.href + "#");
                        R = l;
                    }, 50);
                    return this;
                }
                return n.title;
            },
            value: function(a) {
                if (a !== k) {
                    a = N(a);
                    if (a == "/") a = "";
                    if (h == a && !L) return;
                    R = o;
                    h = a;
                    if (d.autoUpdate || L) {
                        E(o);
                        if (r()) M[d.history ? "pushState" : "replaceState"]({}, "", d.state.replace(/\/$/, "") + (h === "" ? "/" : h));
                        else {
                            K = o;
                            if (H)
                                if (d.history) g.hash = "#" + B(h, o);
                                else
                                    g.replace("#" +
                                        B(h, o));
                            else if (h != u())
                                if (d.history) g.hash = "#" + B(h, o);
                                else g.replace("#" + B(h, o));
                            y && q < 8 && d.history && t(O, 50);
                            if (H) t(function() { K = l; }, 1);
                            else K = l;
                        }
                    }
                    return this;
                }
                if (!P) return null;
                return N(h);
            },
            path: function(a) {
                if (a !== k) {
                    var b = this.queryString(), e = this.hash();
                    this.value(a + (b ? "?" + b : "") + (e ? "#" + e : ""));
                    return this;
                }
                return N(h).split("#")[0].split("?")[0];
            },
            pathNames: function() {
                var a = this.path(), b = a.replace(U, "/").split("/");
                if (a.substr(0, 1) == "/" || a.length === 0) b.splice(0, 1);
                a.substr(a.length - 1, 1) == "/" && b.splice(b.length -
                    1, 1);
                return b;
            },
            queryString: function(a) {
                if (a !== k) {
                    var b = this.hash();
                    this.value(this.path() + (a ? "?" + a : "") + (b ? "#" + b : ""));
                    return this;
                }
                a = h.split("?");
                return a.slice(1, a.length).join("?").split("#")[0];
            },
            parameter: function(a, b, e) {
                var f, p;
                if (b !== k) {
                    var J = this.parameterNames();
                    p = [];
                    b = b ? b.toString() : "";
                    for (f = 0; f < J.length; f++) {
                        var S = J[f], A = this.parameter(S);
                        if (typeof A == "string") A = [A];
                        if (S == a) A = b === null || b === "" ? [] : e ? A.concat([b]) : [b];
                        for (var T = 0; T < A.length; T++) p.push(S + "=" + A[T]);
                    }
                    c.inArray(a, J) == -1 && b !== null &&
                        b !== "" && p.push(a + "=" + b);
                    this.queryString(p.join("&"));
                    return this;
                }
                if (b = this.queryString()) {
                    e = [];
                    p = b.split("&");
                    for (f = 0; f < p.length; f++) {
                        b = p[f].split("=");
                        b[0] == a && e.push(b.slice(1).join("="));
                    }
                    if (e.length !== 0) return e.length != 1 ? e : e[0];
                }
            },
            parameterNames: function() {
                var a = this.queryString(), b = [];
                if (a && a.indexOf("=") != -1) {
                    a = a.split("&");
                    for (var e = 0; e < a.length; e++) {
                        var f = a[e].split("=")[0];
                        c.inArray(f, b) == -1 && b.push(f);
                    }
                }
                return b;
            },
            hash: function(a) {
                if (a !== k) {
                    this.value(h.split("#")[0] + (a ? "#" + a : ""));
                    return this;
                }
                a =
                    h.split("#");
                return a.slice(1, a.length).join("#");
            }
        };
    }();
    c.fn.address = function(v) {
        if (!c(this).attr("address")) {
            var w = function(r) {
                if (r.shiftKey || r.ctrlKey || r.metaKey) return true;
                if (c(this).is("a")) {
                    var s = v ? v.call(this) : /address:/.test(c(this).attr("rel")) ? c(this).attr("rel").split("address:")[1].split(" ")[0] : c.address.state() !== undefined && c.address.state() != "/" ? c(this).attr("href").replace(new RegExp("^(.*" + c.address.state() + "|\\.)"), "") : c(this).attr("href").replace(/^(#\!?|\.)/, "");
                    c.address.value(s);
                    r.preventDefault();
                }
            };
            c(this).click(w).live("click", w).live("submit", function(r) {
                if (c(this).is("form")) {
                    var s = c(this).attr("action");
                    s = v ? v.call(this) : (s.indexOf("?") != -1 ? s.replace(/&$/, "") : s + "?") + c(this).serialize();
                    c.address.value(s);
                    r.preventDefault();
                }
            }).attr("address", true);
        }
        return this;
    };
})(jQuery);

jQuery.fn.recommend = function() {
    var d = arguments[0] || {};
    var q = $(this);
    var h = $("ul.options", q), u = d.l, f = 1, s = [], p = [], g = false, v = u.length, m = $(".loader", q), i = $("h1", q.parent()), b = $("#help_icon");
    k({});
    var r = $(".recom_boton", q);
    r.click(function() {
        if ($(this).hasClass("on")) {
            a();
        }
    });

    function j(l) {
        i.show();
        b.show();
        $(".recline", q).show();
        $("#recom_error").remove();
        m.hide();
        if (l.nivel == f) {
            s.push(l);
            f++;
            if (l.last == "si") {
                a();
                e();
                n();
                return;
            }
        } else {
            if (l.nivel < f && f > 1) {
                s.splice((l.nivel - 1), (s.length - (l.nivel - 1)));
                f = l.nivel;
            }
        }
        k(l);
        e();
        n();
    }

    function k(y) {
        h.empty();
        $(".infobot", q).show();
        $("#recommendation").hide();
        for (var x = 0; x < v; x++) {
            if (u[x].nivel == f && (f == 1 || u[x].tipo == y.tipo)) {
                var l = $("<li><a class='o_" + x + "'>" + u[x].opcion + "</a></li>");
                h.append(l);
            }
        }
        var l = $("li", h), w = l.length, t = (w > 4 && w % 2 == 0) ? 200 : 100;
        l.each(function() {
            var z = $(this);
            z.width(t / w + "%").click(function() {
                var A = z.children().attr("class").replace("o_", "");
                j(u[A]);
            });
        });
    }

    function e() {
        p = [];
        var x = s.length, w = "<a>Inicio</a><span>»</span> ";
        for (var t = 0; t < x; t++) {
            w += (t == (x - 1)) ? s[t].opcion : "<a>" + s[t].opcion + "</a>";
            if (t < (x - 1)) {
                w += "<span>»</span>";
            }
        }
        var l = $("#rec_history");
        l.html(w);
        $("a", l).each(function(y) { $(this).click(function() { j(s[y]); }); });
    }

    function n() {
        if (f == 1) {
            r.removeClass("on");
            return;
        }
        if (!r.hasClass("on")) {
            r.addClass("on");
        }
    }

    function a() {
        if (g) {
            return;
        }
        h.empty();
        var l = $("#recommendation");
        $(".infobot", q).hide();
        l.hide();
        m.show();
        g = true;
        $.ajax({
            type: "POST",
            url: "ajax/recommend",
            data: { actual: s, history: p },
            dataType: "json",
            success: function(w) {
                if (typeof w == "object" && w.id > 0) {
                    i.hide();
                    b.hide();
                    p.push(w.id);
                    $(".img img", q).attr("src", "http://sc.cuevana.tv/box/" + w.id + ".jpg");
                    $(".img a", q).attr("href", w.url);
                    $(".tit a", l).attr("href", w.url).html(w.tit);
                    $(".rate span", q).css("width", Math.round(w.rate * 100 / 5) + "%");
                    var x = ["year", "reparto", "director", "idioma", "duracion", "genero"];
                    for (var t in x) {
                        $("." + x[t], l).html(w[x[t]]);
                    }
                    $(".rank .rk", l).html(Math.round(w.rate * 100) / 100);
                    $(".sinopsis", l).html(o(w.sinopsis, 297));
                    $(".links li a").not(".seen").each(function() { $(this).attr("href", w.url); });
                    $(".links li a.seen").removeClass("sel").unbind("click").click(function() {
                        c.selactButton($(this), { id: w.id });
                        a();
                        return false;
                    }).parent().parent().parent().show();
                    l.show();
                    r.html(r.attr("data-alt"));
                } else {
                    l.before("<p id='recom_error'>No hay más recomendaciones disponibles para las opciones elegidas. Por favor <a>intenta nuevamente</a> cambiando tus parámetros.</p>");
                    $("#recom_error a").click(function() {
                        $(this).parent().remove();
                        j(s[s.length - 1]);
                    });
                }
            },
            error: function() {
                l.before("<p id='recom_error'>Ha ocurrido un error. Por favor <a>intenta nuevamente</a>.</p>");
                $("#recom_error a").click(function() {
                    $(this).parent().remove();
                    a();
                });
            },
            complete: function() {
                m.hide();
                g = false;
            }
        });
    }

    function o(l, t) { return (l.length > t) ? l.substr(0, t) + "…" : l; }
};

jQuery.fn.rowbox = function() {
    var d = arguments[0] || {};
    var o = $(this);
    var b = $(".menu", o), i = $(".in", o), f = $(".boxes", i), x = d.l, j = d.width || 122, z = d.padding || 10, h = $.browser.opera, u = d.serie || false, s = "reciente", p = d.set || ["genero", "idioma"];
    var a = $("#blob" + (u ? "_serie" : ""));
    $("li:not(.tit) a", b).each(function() {
        var l = $(this), t = l.attr("name");
        if (t != null) {
            l.click(function() {
                e(t);
                return false;
            });
        }
    });
    e(s);

    function k(l) {
        $("li:not(.tit) a", b).removeClass("sel");
        $('a[name="' + l + '"]', b).addClass("sel");
    }

    function e(A) {
        k(A);
        var B = x[A], w = 0, t = "";
        for (var l in B) {
            t += '<a href="' + B[l].url + '" id="' + (u ? "e" : "s") + B[l].id + '"><span class="img"><img src="img/blank.gif" name="http://sc.cuevana.tv/box/' + (u ? B[l].s_id : B[l].id) + '.jpg" />' + ((B[l].playable) ? '<div class="play_label"><span></span></div>' : "") + ((B[l].hd > 0) ? '<div class="hd_label">HD</div>' : "") + '</span><span class="tit">' + B[l].tit + "</span>" + (u ? '<span class="tit2">' + B[l].serie + "</span>" : "") + "</a>";
            w++;
        }
        i.remove();
        $(".box", o).html('<div class="in"><div class="boxes"></div></div>');
        i = $(".in", o);
        f = $(".boxes", i).width(w * (j + z) - z).html(t);
        $("a", f).hover(function(C) { r(C, this); }, function() { y(); }).last().addClass("last");
        i.jScrollPane({
            onScroll: function(C) {
                n();
                y();
                q();
            }
        }).carousel();
        n();
        s = A;
    }

    function q() {
        if (typeof $.updateCar == "function") {
            $.updateCar();
        }
    }

    function r(A, C) {
        C = $(C);
        var B = C.offset(), w = window.innerWidth ? window.innerWidth : document.body.clientWidth, D;
        for (var t in x[s]) {
            if (x[s][t].id == g(C)) {
                D = x[s][t];
                break;
            }
        }
        $(".txt", a).html(m(D.txt, 280));
        $(".rate span", a).css("width", Math.round(D.rate * 100 / 5) + "%");
        for (var l in p) {
            $("." + p[l], a).html(D[p[l]]);
        }
        a.css({ top: B.top, left: B.left + ((A.pageX >= (w / 2)) ? -a.outerWidth() : C.outerWidth()) }).removeClass("l").removeClass("r").addClass(((A.pageX >= (w / 2)) ? "l" : "r")).show();
    }

    function y() { a.hide(); }

    function g(l) { return l.attr("id").replace(/^(s|e)/i, ""); }

    function n() {
        $(".img", f).not(".loaded").each(function() {
            var l = $(this);
            if (v(l, i)) {
                c(l);
            }
        });
    }

    function v(B, A, w) {
        if (!$(B).length || !$(A).length) {
            return false;
        }
        var D = A.offset().left, C = D + A.width(), l = $(B).offset().left, t = l + $(B).width();
        return w ? ((t >= D) && (l <= C) && (t <= C) && (l >= D)) : ((t >= D) && (l <= C));
    }

    function c(w) {
        var t = $("img", w);
        if (t.attr("name").match(/.jpg$/i)) {
            var l = t[0];
            t.attr("src", t.attr("name")).load(function() {
                if (!h) {
                    if (!l.complete || typeof l.naturalWidth == "undefined" || l.naturalWidth == 0) {
                        $(this).error();
                    } else {
                        $(this).reflect({ height: 0.15, opacity: 0.25 });
                    }
                } else {
                    $(this).reflect({ height: 0.15, opacity: 0.25 });
                }
            });
            w.addClass("loaded");
        }
    }

    function m(l, t) { return (l.length > t) ? l.substr(0, t) + "…" : l; }
};

(function($) {
    var helper = {}, current, title, tID, IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent), track = false;
    $.tooltip = { blocked: false, defaults: { delay: 200, fade: false, showURL: true, extraClass: "", top: 15, left: 15, id: "tooltip" }, block: function() { $.tooltip.blocked = !$.tooltip.blocked; } };
    $.fn.extend({
        tooltip: function(settings) {
            settings = $.extend({}, $.tooltip.defaults, settings);
            createHelper(settings);
            return this.each(function() {
                $.data(this, "tooltip", settings);
                this.tOpacity = helper.parent.css("opacity");
                this.tooltipText = this.title;
                $(this).removeAttr("title");
                this.alt = "";
            }).mouseover(save).mouseout(hide).click(hide);
        },
        fixPNG: IE ? function() {
            return this.each(function() {
                var image = $(this).css('backgroundImage');
                if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
                    image = RegExp.$1;
                    $(this).css({ 'backgroundImage': 'none', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" }).each(function() {
                        var position = $(this).css('position');
                        if (position != 'absolute' && position != 'relative') $(this).css('position', 'relative');
                    });
                }
            });
        } : function() { return this; },
        unfixPNG: IE ? function() { return this.each(function() { $(this).css({ 'filter': '', backgroundImage: '' }); }); } : function() { return this; },
        hideWhenEmpty: function() { return this.each(function() { $(this)[$(this).html() ? "show" : "hide"](); }); },
        url: function() { return this.attr('href') || this.attr('src'); }
    });

    function createHelper(settings) {
        if (helper.parent) return;
        helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();
        if ($.fn.bgiframe) helper.parent.bgiframe();
        helper.title = $('h3', helper.parent);
        helper.body = $('div.body', helper.parent);
        helper.url = $('div.url', helper.parent);
    }

    function settings(element) { return $.data(element, "tooltip"); }

    function handle(event) {
        if (settings(this).delay) tID = setTimeout(show, settings(this).delay);
        else
            show();
        track = !!settings(this).track;
        $(document.body).bind('mousemove', update);
        update(event);
    }

    function save() {
        if ($.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler)) return;
        current = this;
        title = this.tooltipText;
        if (settings(this).bodyHandler) {
            helper.title.hide();
            var bodyContent = settings(this).bodyHandler.call(this);
            if (bodyContent.nodeType || bodyContent.jquery) {
                helper.body.empty().append(bodyContent);
            } else {
                helper.body.html(bodyContent);
            }
            helper.body.show();
        } else if (settings(this).showBody) {
            var parts = title.split(settings(this).showBody);
            helper.title.html(parts.shift()).show();
            helper.body.empty();
            for (var i = 0, part; (part = parts[i]); i++) {
                if (i > 0) helper.body.append("<br/>");
                helper.body.append(part);
            }
            helper.body.hideWhenEmpty();
        } else {
            helper.title.html(title).show();
            helper.body.hide();
        }
        if (settings(this).showURL && $(this).url()) helper.url.html($(this).url().replace('http://', '')).show();
        else
            helper.url.hide();
        helper.parent.addClass(settings(this).extraClass);
        if (settings(this).fixPNG) helper.parent.fixPNG();
        handle.apply(this, arguments);
    }

    function show() {
        tID = null;
        if ((!IE || !$.fn.bgiframe) && settings(current).fade) {
            if (helper.parent.is(":animated")) helper.parent.stop().show().fadeTo(settings(current).fade, current.tOpacity);
            else
                helper.parent.is(':visible') ? helper.parent.fadeTo(settings(current).fade, current.tOpacity) : helper.parent.fadeIn(settings(current).fade);
        } else {
            helper.parent.show();
        }
        update();
    }

    function update(event) {
        if ($.tooltip.blocked) return;
        if (event && event.target.tagName == "OPTION") {
            return;
        }
        if (!track && helper.parent.is(":visible")) {
            $(document.body).unbind('mousemove', update);
        }
        if (current == null) {
            $(document.body).unbind('mousemove', update);
            return;
        }
        helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");
        var left = helper.parent[0].offsetLeft;
        var top = helper.parent[0].offsetTop;
        if (event) {
            left = event.pageX + settings(current).left;
            top = event.pageY + settings(current).top;
            var right = 'auto';
            if (settings(current).positionLeft) {
                right = $(window).width() - left;
                left = 'auto';
            }
            helper.parent.css({ left: left, right: right, top: top });
        }
        var v = viewport(), h = helper.parent[0];
        if (v.x + v.cx < h.offsetLeft + h.offsetWidth) {
            left -= h.offsetWidth + 20 + settings(current).left;
            helper.parent.css({ left: left + 'px' }).addClass("viewport-right");
        }
        if (v.y + v.cy < h.offsetTop + h.offsetHeight) {
            top -= h.offsetHeight + 20 + settings(current).top;
            helper.parent.css({ top: top + 'px' }).addClass("viewport-bottom");
        }
    }

    function viewport() { return { x: $(window).scrollLeft(), y: $(window).scrollTop(), cx: $(window).width(), cy: $(window).height() }; }

    function hide(event) {
        if ($.tooltip.blocked) return;
        if (tID) clearTimeout(tID);
        current = null;
        var tsettings = settings(this);

        function complete() { helper.parent.removeClass(tsettings.extraClass).hide().css("opacity", ""); }

        if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
            if (helper.parent.is(':animated')) helper.parent.stop().fadeTo(tsettings.fade, 0, complete);
            else
                helper.parent.stop().fadeOut(tsettings.fade, complete);
        } else
            complete();
        if (settings(this).fixPNG) helper.parent.unfixPNG();
    }
})(jQuery);

jQuery.fn.filters = function() {
    var l = arguments[0] || {};
    var j = $(this);
    var g = l.f || [], h = {}, c = l.sel || {};
    k();

    function k() {
        for (var t in g) {
            var p = a(t);
            var q = g[t], o = q.length, s = $("ul", p);
            if (typeof c[t] == "undefined") {
                c[t] = [];
            }
            if (o > 0) {
                var f = $('<li><a class="all ' + (!c[t].length ? "sel" : "") + '" name="' + t + '"><span></span>' + lg.todos + "</a></li>");
                $("a", f).click(function() {
                    i(this, true);
                    return false;
                });
                s.append(f);
                for (var u = 0; u < o; u++) {
                    var r = $('<li><a href="#" name="' + t + "_" + u + '" ' + ((c[t].indexOf(g[t][u]["id"]) != -1) ? 'class="sel"' : "") + "><span></span>" + g[t][u].nombre + "</a></li>");
                    $("a", r).click(function() {
                        i(this);
                        return false;
                    });
                    s.append(r);
                }
                s.jScrollPane();
            }
        }
    }

    function a(f) {
        Object.size = function(p) {
            var o = 0, m;
            for (m in p) {
                if (p.hasOwnProperty(m)) {
                    o++;
                }
            }
            return o;
        };
        h[f] = $("<div></div>");
        j.append(h[f]);
        var b = (Object.size(h) < Object.size(g)) ? '<div class="sep"></div>' : "";
        h[f].html('<div class="block_tit">' + lg[f] + '</div><ul class="block"></ul>' + b);
        return h[f];
    }

    function i(f, r) {
        f = $(f);
        var m = f.attr("name").split("_"), u = m[0];
        if (r) {
            $("a", f.parent().parent()).removeClass("sel");
            f.addClass("sel");
            c[u] = [];
            e();
            return;
        }
        if (c[u] == "undefined") {
            c[u] = [];
        }
        var p = m[1], v = c[u], t = g[u][p], b = v.indexOf(t.id);
        if (b != -1) {
            v.splice(b, 1);
            f.removeClass("sel");
        } else {
            v.push(t.id);
            f.addClass("sel");
        }
        var q = f.parent().parent();
        if (v.length > 0) {
            $(".all", q).removeClass("sel");
        } else {
            $(".all", q).addClass("sel");
        }
        e();
    }

    function e() {
        if (!$("#filter_pop").length) {
            var b = $('<div id="filter_pop"><div>Haz click en Finalizar cuando termines de filtrar</div><a class="finalizar boton">Finalizar</a><a class="cancelar boton">Cancelar</a></div>').appendTo("body");
            $("#list").css("opacity", 0.5);
            $("a.finalizar", b).click(function() {
                d();
                $("#filter_pop").remove();
                $("#list").css("opacity", 1);
            }).focus();
            $("a.cancelar", b).click(function() {
                $("#filter_pop").remove();
                $("#list").css("opacity", 1);
            });
            $(window).bind("hashchange.filter", function() { $("#filter_pop").remove(); });
        }
    }

    function d() {
        var m = window.location.href.replace(/\/page:([0-9]+)/i, "").replace(/\/filters:([^\/]*)/i, "");
        var p = "";
        for (var b in c) {
            if (c[b].length > 0) {
                if (p.length > 0) {
                    p += "|";
                }
                var o = "";
                for (n in c[b]) {
                    if (o.length > 0) {
                        o += ",";
                    }
                    o += c[b][n];
                }
                p += b + "=" + o;
            }
        }
        window.location.href = m + ((p.length > 0) ? "/filters:" + p : "");
    }
};

jQuery.fn.serieList = function() {
    var k = arguments[0] || {};
    var j = $(this), h = k.e, d = k.l, c = [];
    for (var f in d) {
        c.push(f);
    }
    g();

    function g() {
        var m = c.length, l = "";
        for (var e = 0; e < m; e++) {
            l += '<li><a name="temp_' + c[e] + '">' + lg.temporada + " " + c[e] + "</a></li>";
        }
        j.html(l);
        $("a", j).click(function() { a($(this).attr("name").replace("temp_", "")); });
        if (m > 0) {
            a(c[0]);
        }
    }

    function a(p) {
        var e = d[p], q = e.length, m = "";
        for (var l = 0; l < q; l++) {
            m += '<li><a href="' + e[l].url + '"><span class="rate"><span style="width:' + Math.round(e[l].rate * 100 / 5) + '%"></span></span><span class="num">' + e[l].num + '</span><span class="tit">' + e[l].tit + (e[l].playable > 0 ? ' <span class="play_label_search"><span></span></span>' : "") + (e[l].hd > 0 ? ' <span class="hd">HD</span>' : "") + "</span></a></li>";
        }
        h.html(m);
        $("a.sel", j).removeClass("sel");
        $("a[name=temp_" + p + "]", j).addClass("sel");
    }

    function b(e, i) { return (e.length > i) ? e.substr(0, i) + "…" : e; }
};

jQuery.fn.list = function() {
    var p = arguments[0] || {};
    var C = $(this), H = p.l, k = p.l, x = k.length, K = $(".pag", C), m = p.limit || 20, y = $("ul", C), j = $(".sample", y), b = ((p.page > 0) ? parseInt(p.page) : null) || 1, A = p.orden, L = $(".orderby .by", C), F = p.o || false, N = "", P = false, q = p.set || ["tit", "ano", "duracion", "genero"], B = p.tipo, w = p.total || 0, v = false;
    if (L.length) {
        I();
    }
    if (!F) {
        if (p.type == "msg" && p.seg != "undefined") {
            var D = p.seg, O = [], G = H.length - 1;
            if (G > 0) {
                do {
                    for (var J in D) {
                        if (D[J] == H[G].u_id) {
                            O.push(G);
                            break;
                        }
                    }
                } while (--G);
                for (var J in O) {
                    var G = O[J];
                    H.unshift(H[G]);
                    H.splice(G + 1, 1);
                }
            }
        }
        z(b);
    } else {
        g(F);
    }

    function M(i) {
        $("li", y).not(".sample, .loader").remove();
        var a = $(".loader", y);
        a.show();
        $.ajax({
            url: "ajax/get_" + p.get,
            type: "POST",
            data: { id: p.id, tipo: B },
            dataType: "json",
            success: function(l) {
                k = l;
                H = k;
                v = true;
                z(i);
            },
            error: function() {
                if (p.errormsg) {
                    y.append('<li class="nomsg">' + p.errormsg + "</li>");
                }
            },
            complete: function() { a.hide(); }
        });
    }

    function z(U, S) {
        $(".showpop").remove();
        if (U > 1 && !v && p.get != null) {
            M(U);
            return;
        }
        x = (!v && w > m) ? w : H.length;
        var t = (U - 1) * m, l = (t + m) < x ? (t + m) : x;
        $("li", y).not(".sample, .loader").remove();
        for (var o = t; o < l; o++) {
            var V = j.clone().removeClass("sample").show();
            y.append(V);
            if (o < (t + 5)) {
                V.addClass("ban");
            }
            for (var a in q) {
                $("." + q[a], V).html(H[o][q[a]]);
            }
            if (o % 2 != 0) {
                V.addClass("row2");
            }
            $(".rank .num", V).html(o + 1);
            if (H[o].id && p.type == null) {
                $(".img img", V).attr("src", "http://sc.cuevana.tv/box/" + H[o].id + ".jpg");
            }
            if (H[o].txt && p.type == null) {
                $(".txt", V).html(E(H[o].txt, 250));
            }
            if (H[o].rate != null) {
                $(".rate span", V).css("width", Math.round(H[o].rate * 20) + "%");
            }
            if (H[o].url && p.type != "lista") {
                $("a", V).attr("href", H[o].url);
            }
            switch (p.type) {
            case "msg":
                if (H[o].u_id) {
                    $(".img img", V).attr("src", "/avatar/" + H[o].u_id);
                }
                if (H[o].usuario) {
                    $(".usuario", V).html(H[o].usuario);
                }
                if (H[o].status) {
                    V.addClass(H[o].status);
                }
                $(".txt", V).html(((H[o].last_act == "sent") ? "<span>»</span>" : "") + H[o].txt);
                break;
            case "com":
                if (H[o].u_id) {
                    $(".img img", V).attr("src", "/avatar/" + H[o].u_id);
                }
                if (H[o].usuario) {
                    $(".usuario", V).html('<a href="#!/usuarios/' + H[o].usuario + '">' + H[o].usuario + "</a>");
                }
                if (H[o].txt) {
                    $(".txt", V).html(e(H[o].txt).replace(/\[spoiler\]((.|[\n\r])*?)\[\/spoiler\]/gi, '<div class="spoiler"><div class="button"><a class="boton">Spoiler</a></div><div class="text"><div class="titr">Spoiler</div>$1</div></div>'));
                }
                $(".txt .spoiler a", V).click(function() {
                    $(this).parent().hide();
                    $(this).parent().parent().children(".text").show();
                });
                $("a.warn", V).attr("data-id", H[o].id);
                break;
            case "fav":
                $(".img img", V).attr("src", "http://sc.cuevana.tv/box/" + (H[o].s_id || H[o].id) + ".jpg");
                $("a", V).not("del").attr("href", H[o].url);
                var T = $("a.del", V);
                T.attr("id", "n_" + H[o].id);
                T.labeltop({ clas: "labeldark" });
                c.setactButton(T, true, { id: H[o].id, tipo: B });
                T.click(function() {
                    $(this).parent().parent().remove();
                    f($(this).attr("id").replace("n_", ""));
                });
                break;
            case "usercrit":
                $(".tit a", V).html(H[o].tit).attr("href", H[o].url);
                $("img", V).attr("src", "http://sc.cuevana.tv/box/" + H[o].id + ".jpg");
                if (H[o].txt) {
                    $(".txt", V).html(e(H[o].txt).replace(/\[spoiler\]((.|[\n\r])*?)\[\/spoiler\]/gi, '<div class="spoiler"><div class="button"><a class="boton">Spoiler</a></div><div class="text"><div class="titr">Spoiler</div>$1</div></div>'));
                }
                $(".txt .spoiler a").click(function() {
                    $(this).parent().hide();
                    $(this).parent().parent().children(".text").show();
                });
                break;
            case "user":
                $(".img img", V).attr("src", "/avatar/" + H[o].id);
                $(".tit", V).html(H[o].usuario);
                break;
            case "avatars":
                $("img", V).attr("src", "http://sc.cuevana.tv/avatar/def/" + H[o] + ".png");
                $("a", V).attr("data-id", H[o]).click(function() { c.selAvatar(this); });
                break;
            }
        }
        if (p.type == "com") {
            $("li", y).hover(function() { $("a.warn", this).css({ display: "block" }); }, function() {
                var i = $("a.warn", this);
                if (!i.hasClass("sel")) {
                    i.hide();
                }
            });
            $("a.warn", y).each(function() { $(this).showPop({ id: $(this).attr("data-id"), tipo: B, showid: p.id }); }).labeltop({ clas: "labeldark" });
        }
        if (p.type == "com" || p.type == "usercrit") {
            $("li .txt", y).each(function(n) { $("a.more", this).click(function() { $(this).parent().html(H[t + n - 1].txt); }); });
        }
        $(".cant", C).html((x > 0 ? (t + 1) : t) + " - " + l);
        $(".total", C).html(x);
        if (x == 0) {
            r();
        } else {
            u(U);
        }
        if (S) {
            window.scrollTo(0, C.offset().top);
        }
    }

    function e(a) {
        if (a.indexOf("[spoiler]") != -1) {
            return a;
        }
        return (a.length > 320) ? a.substr(0, 320) + '… <a class="more">más »</a>' : a;
    }

    function r() {
        if (p.nomsg) {
            y.append('<li class="nomsg">' + p.nomsg + "</li>");
        }
    }

    function u(l) {
        var t = Math.ceil(x / m), S = 2;
        K.empty();
        if (l > 1) {
            var T = $('<a class="prev" data-page="' + (l - 1) + '"></a>');
            K.append(T);
        }
        if ((l + S) > 1 && l > 1) {
            var T = $('<a data-page="1">1</a>');
            K.append(T);
            if ((l - S) > 2) {
                K.append("<span>...</span>");
            }
        }
        var o = l > S ? ((l - S) > 1 ? (l - S) : 2) : l;
        for (var s = o; s < l; s++) {
            var T = $('<a data-page="' + s + '">' + s + "</a>");
            K.append(T);
        }
        K.append('<span class="actual">' + l + "</span>");
        o = l < t ? ((l + S) < t ? (l + S) : t) : t;
        for (var s = (l + 1); s <= o; s++) {
            var T = $('<a data-page="' + s + '">' + s + "</a>");
            K.append(T);
        }
        if ((l + S) < t) {
            var T = $('<a data-page="' + t + '">' + t + "</a>");
            if ((l + S) != (t - 1)) {
                K.append("<span>…</span>");
            }
            K.append(T);
        }
        if (l < t) {
            var T = $('<a class="next" data-page="' + (l + 1) + '"></a>');
            K.append(T);
        }
        $("a", K).click(function() {
            var a = parseInt($(this).attr("data-page"));
            if (a > 0) {
                z(a, true);
            }
        });
    }

    function I() {
        var l = "", a = 0;
        for (var o in A) {
            l += ((a > 0) ? ", " : "") + '<a data-id="' + o + '">' + A[o] + "</a>";
            a++;
        }
        L.html(l);
        $("a", L).click(function() { g($(this).attr("data-id")); });
    }

    function g(a) {
        I();
        if (N == a && !P) {
            H.sort(h(a));
            P = true;
            $("[data-id=" + a + "]", L).addClass("down");
        } else {
            H.sort(d(a));
            P = false;
            $("[data-id=" + a + "]", L).addClass("up");
        }
        N = a;
        z(1);
    }

    function R() {
        if (N.length > 0) {
            if (P) {
                H.sort(h(N));
            } else {
                H.sort(d(N));
            }
        }
    }

    function d(a) {
        if (a != "rate" && a != "ano" && a != "duracion" && a != "puntaje" && a != "usuarios" && a != "priv") {
            return function(n, l) {
                var i = Q(n[a]), o = Q(l[a]);
                if (i < o) {
                    return -1;
                }
                if (i > o) {
                    return 1;
                }
                return 0;
            };
        } else {
            return function(n, l) {
                var i = parseFloat(n[a]), o = parseFloat(l[a]);
                if (i < o) {
                    return -1;
                }
                if (i > o) {
                    return 1;
                }
                return 0;
            };
        }
    }

    function h(a) {
        if (a == "tit" || a == "nombre") {
            return function(n, l) {
                var i = Q(n[a]), o = Q(l[a]);
                if (i > o) {
                    return -1;
                }
                if (i < o) {
                    return 1;
                }
                return 0;
            };
        } else {
            return function(n, l) {
                var i = parseFloat(n[a]), o = parseFloat(l[a]);
                if (i > o) {
                    return -1;
                }
                if (i < o) {
                    return 1;
                }
                return 0;
            };
        }
    }

    function E(a, i) { return (a.length > i) ? a.substr(0, i) + "…" : a; }

    function f(i) {
        x = k.length;
        for (var a = 0; a < x; a++) {
            if (k[a].id == i) {
                k.splice(a, 1);
                break;
            }
        }
        H = k;
        z(b);
    }

    function Q(i) {
        i = i.toLowerCase().split("");
        strAccentsOut = [];
        strAccentsLen = i.length;
        var a = "àáòóôöèéçìíîïùúüñ¿¡", l = ["a", "a", "o", "o", "o", "o", "e", "e", "e", "c", "i", "i", "i", "i", "u", "u", "u", "", ""];
        for (var n = 0; n < strAccentsLen; n++) {
            if (a.indexOf(i[n]) != -1) {
                strAccentsOut[n] = l[a.indexOf(i[n])];
            } else {
                strAccentsOut[n] = i[n];
            }
        }
        strAccentsOut = strAccentsOut.join("");
        return strAccentsOut;
    }

    $.extend({
        lazyTxt: function(a, i) {
            $.ajax({
                url: "ajax/lazytxt",
                type: "POST",
                data: { order: a, tipo: i },
                dataType: "json",
                success: function(n) {
                    var o = k.length;
                    for (var l = 0; l < o; l++) {
                        k[l].txt = n[l].txt;
                    }
                    z(1);
                }
            });
        },
        addListData: function(a, l, i) {
            if (l == "append") {
                k = k.concat(a);
            } else {
                k = a.concat(k);
            }
            if (i) {
                b = Math.ceil(k.length / m);
            }
            H = k;
            z(b);
        }
    });
};

jQuery.fn.rate = function() {
    var a = arguments[0] || {};
    this.each(function() {
        var k = $("a", this), d = k.length, h = a.defecto ? a.defecto - 1 : -1, i = a.label || [], b = $(".txt", this), j = $("input", this);
        l(k);

        function l() {
            k.each(function(m) { $(this).hover(function() { n(m); }, function() { f(); }).click(function() { e(m); }); });
            if (h >= 0) {
                e(h);
            }
        }

        function n(m) {
            if (m <= d && m >= 0) {
                k.removeClass("rated");
                for (var o = m; o >= 0; o--) {
                    k.eq(o).addClass("hover");
                }
            }
            g(m);
        }

        function f() {
            k.removeClass("hover");
            if (h >= 0) {
                e(h);
            }
            if (i.length > 0) {
                b.html(i[0]);
            }
        }

        function e(m) {
            k.removeClass("hover").removeClass("rated");
            if (m <= d && m >= 0) {
                for (var p = m; p >= 0; p--) {
                    k.eq(p).addClass("rated");
                }
                if (m == h) {
                    return;
                }
                h = m;
                if (j.length > 0) {
                    j.val(m + 1);
                } else {
                    var o = c.newAjaxCallId();
                    a.data.puntaje = m + 1;
                    $.ajax({ type: "POST", url: "ajax/rate", data: a.data, error: function(q, s, r) { t.ajaxError(true, s); }, complete: function() { c.delAjaxCall(o); } });
                }
            }
            g(h);
        }

        function g(m) {
            if (i.length > 0) {
                b.html(i[m + 1]);
            }
        }
    });
};

jQuery.fn.tabs = function() {
    var m = arguments[0] || {};
    var k = $(this), f = $("> ul", k);
    var c = $("> li", f), h = c.length, e = $(".bg", k), a = m.sel, d = 1;
    if (m.main) {
        var i = function(l) {
            l.addClass("sel");
            window.location.href = l.attr("href");
        };
        d = 5;
    } else {
        var i = b;
    }
    j();

    function j() {
        if (!m.main) {
            var l = 2;
            c.each(function() { l += $(this).width(); });
            $("> ul", k).width(l);
        }
        if (h > 0) {
            var o = (a >= 0) ? parseInt(a) : 0;
            g(c.eq(o));
        }
        $("> a", c).unbind("click").click(function() {
            g($(this).parent(), true);
            return false;
        });
    }

    function g(p, o) {
        $("> a.sel", c).removeClass("sel");
        var n = p.offset(), l = $("> a", p);
        l.addClass("sel");
        e.animate({ left: n.left - f.offset().left - d, width: p.width() }, 200, function() {
            if (o) {
                i(l);
            }
        });
        if (!m.main && !o) {
            i(l);
        }
    }

    function b(l) {
        var n = $(".content .contain", k.parent());
        l = l.attr("class").replace(" sel", "");
        n.children().hide();
        n.children("." + l).fadeIn(200);
    }
};

jQuery.fn.labeltop = function() {
    var a = arguments[0] || {};
    var b = a.clas || "labeltop", c;
    this.each(function() {
        var e = $(this);
        e.hover(function() { d(e); }, function() { f(); }).mousedown(function() { f(); });

        function d(i) {
            var l = i.hasClass("sel") ? i.attr("data-alt") : i.attr("data-title"), o = i.offset();
            if (l == "undefined" || l.length == 0) {
                return;
            }
            c = $('<div id="labeltop" class="' + b + '"><div class="label">' + l + '</div><div class="arrow"></div></div>');
            $("body").append(c);
            var n = (o.left + i.outerWidth() / 2);
            var j = n + (c.outerWidth() / 2), h = n - (c.outerWidth() / 2);
            c.css({ top: o.top, left: (j > g()) ? (o.left + i.outerWidth()) - c.outerWidth() : ((h < 0) ? o.left : n - (c.outerWidth() / 2)) });
            if (j > g()) {
                c.addClass("right");
            } else {
                if (h < 0) {
                    c.addClass("left");
                }
            }
        }

        function f() {
            if (c != null) {
                c.remove();
            }
            c = null;
        }

        function g() { return window.innerWidth ? window.innerWidth : document.body.clientWidth; }
    });
};
(function() {
    var a = {
        getSelection: function() {
            var b = this.jquery ? this[0] : this;
            return (("selectionStart" in b && function() {
                var c = b.selectionEnd - b.selectionStart;
                return { start: b.selectionStart, end: b.selectionEnd, length: c, text: b.value.substr(b.selectionStart, c) };
            }) || (document.selection && function() {
                b.focus();
                var e = document.selection.createRange();
                if (e == null) {
                    return { start: 0, end: b.value.length, length: 0 };
                }
                var d = b.createTextRange();
                var c = d.duplicate();
                d.moveToBookmark(e.getBookmark());
                c.setEndPoint("EndToStart", d);
                return { start: c.text.length, end: c.text.length + e.text.length, length: e.text.length, text: e.text };
            }) || function() { return { start: 0, end: b.value.length, length: 0 }; })();
        },
        replaceSelection: function() {
            var c = this.jquery ? this[0] : this;
            var b = arguments[0] || "";
            return (("selectionStart" in c && function() {
                c.value = c.value.substr(0, c.selectionStart) + b + c.value.substr(c.selectionEnd, c.value.length);
                return this;
            }) || (document.selection && function() {
                c.focus();
                document.selection.createRange().text = b;
                return this;
            }) || function() {
                c.value += b;
                return this;
            })();
        }
    };
    jQuery.each(a, function(b) { jQuery.fn[b] = this; });
})();
jQuery.fn.extend({
    insertAtCaret: function(a) {
        return this.each(function(d) {
            if (document.selection) {
                this.focus();
                sel = document.selection.createRange();
                sel.text = a;
                this.focus();
            } else {
                if (this.selectionStart || this.selectionStart == "0") {
                    var c = this.selectionStart;
                    var b = this.selectionEnd;
                    var e = this.scrollTop;
                    this.value = this.value.substring(0, c) + a + this.value.substring(b, this.value.length);
                    this.focus();
                    this.selectionStart = c + a.length;
                    this.selectionEnd = c + a.length;
                    this.scrollTop = e;
                } else {
                    this.value += a;
                    this.focus();
                }
            }
        });
    }
});

jQuery.fn.featured = function() {
    var o = arguments[0] || {};
    var n = $(this), g = $("ul", n), l = $("li", g), b, c = o.speed || 400, d = o.delay || 7000, e = -1;
    m();

    function m() {
        g.width((l.length + 1) * n.width());
        i();
        a(0);
    }

    function i() {
        var s = $('<div class="ref"><ul></ul></div>');
        n.append(s);
        var r = $("li", g).length;
        for (var q = 0; q < r; q++) {
            var p = $("<li><a></a></li>");
            s.append(p);
        }
        $("a", s).click(function() { a($("a", s).index($(this))); });
        b = s;
    }

    function h(q) {
        var p = l.eq(q);
        if (!p.hasClass("loaded")) {
            p.css({ backgroundImage: "url(" + p.attr("data-img") + ")" }).addClass("loaded");
        }
        if (q < l.length) {
            var p = l.eq(q + 1);
            if (!p.hasClass("loaded")) {
                setTimeout(function() { p.css({ backgroundImage: "url(" + p.attr("data-img") + ")" }).addClass("loaded"); }, 3500);
            }
        }
    }

    function a(r, q) {
        if (q) {
            var p = l.eq(0).clone();
            g.append(p);
            l = $("li", g);
            r = l.length - 1;
        }
        f(q ? 0 : r);
        h(q ? 0 : r);
        $(".in", l.eq(r)).css({ bottom: "-300px" });
        $(".tit", l.eq(r)).hide();
        g.stop(false, false).animate({ left: -r * n.width() }, c, function() { k(r, q); });
    }

    function f(q) {
        var p = $("a", b);
        p.removeClass("sel");
        p.eq(q).addClass("sel");
    }

    function k(q, p) {
        $(".in", l.eq(q)).animate({ bottom: 0 }, 300, function() {
            $(".tit", l.eq(q)).fadeIn(200, function() {
                if (p) {
                    g.css({ left: 0 });
                    $("li", g).last().remove();
                    l = $("li", g);
                    q = 0;
                }
                j(q);
            });
        });
    }

    function j(r) {
        var p, q = false;
        if (r < (l.length - 1)) {
            p = r + 1;
        } else {
            p = 0;
            q = true;
        }
        e = p;
        setTimeout(function() {
            if (e == p) {
                a(p, q);
            }
        }, d);
    }
};

jQuery.fn.news = function() {
    var k = arguments[0] || {};
    var i = $(this);
    var d = k.l || {};
    b();

    function b() {
        var p = "", m = 0;
        for (var o in d) {
            p += '<div class="wbox dark"><div class="titbar"><div class="tit">' + ((m == 0) ? "Esta semana" : "Semana del " + d[o]["fecha"]) + '</div></div><div class="darkbox"><div class="row"><ul>';
            var l = d[o]["data"];
            for (var q in l) {
                p += '<li><div data-img="http://sc.cuevana.tv/cache/noticias/' + l[q].id + '.jpg"><a href="' + l[q].url + '"> 				<span class="txt"> 				<span class="tit">' + l[q].tit + '</span> 				<span class="subtit">' + l[q].subtit + '</span> 				</span> 				<span class="com">' + l[q].com + "</span> 				</a></div></li>";
            }
            p += "</ul></div></div></div>";
            m++;
        }
        i.html(p);
        $("ul", i).each(function() {
            var n = $(this);
            n.width(j($("li", n)));
        });
        $(".row", i).jScrollPane({
            onScroll: function(n) {
                h();
                f();
            }
        }).carousel({ speed: 236 });
        $("li a .txt", i).vAlign();
        $("li a", i).hover(function() { $(this).animate({ opacity: 1 }, 250); }, function() { $(this).animate({ opacity: 0 }, 250); });
        h();
    }

    function j(o) {
        var m = o.length, l = 0;
        for (var n = 0; n < m; n++) {
            l += o.eq(n).outerWidth() + 10;
        }
        return l;
    }

    function f() {
        if (typeof $.updateCar == "function") {
            $.updateCar();
        }
    }

    function a(l) { return l.attr("id").replace(/^(s|e)/i, ""); }

    function h() {
        $("li div", i).not(".loaded").each(function() {
            var l = $(this);
            if (e(l, l.parent().parent().parent())) {
                g(l);
            }
        });
    }

    function e(p, o, n) {
        if (!$(p).length || !$(o).length) {
            return false;
        }
        var r = o.offset().left, q = r + o.width(), l = $(p).offset().left, m = l + $(p).width();
        return n ? ((m >= r) && (l <= q) && (m <= q) && (l >= r)) : ((m >= r) && (l <= q));
    }

    function g(m) {
        var l = m;
        if (l.attr("data-img").match(/.jpg$/i)) {
            l.css("background-image", "url(" + l.attr("data-img") + ")").addClass("loaded");
        }
    }

    function c(l, o) { return (l.length > o) ? l.substr(0, o) + "…" : l; }
};

jQuery.fn.carousel = function() {
    var a = arguments[0] || {};
    this.each(function() {
        var i = $(this), j = i.data("jsp"), v, m = $(".jspPane", i);
        var f = i.width(), b = i.offset(), r = b.left, w = b.left + f, k = false, s = a.speed || 132;
        m.parent().prepend('<div class="rightpane"></div><div class="leftpane"></div>');
        var e = $(".rightpane", i), d = $(".leftpane", i);
        d.hover(function(p) { g(p); }, function(p) { n(); });
        e.hover(function(p) { u(p); }, function(p) { n(); });

        function g(p) { v = setInterval(function() { h(p); }, 1); }

        function u(p) { v = setInterval(function() { l(p); }, 1); }

        function n() { clearInterval(v); }

        function h(p) {
            q(p);
            c();
        }

        function l(p) {
            o(p);
            c();
        }

        function c() {
            if (m.offset().left + m.children().width() > w) {
                e.show();
            } else {
                e.hide();
            }
            if (m.offset().left < r) {
                d.show();
            } else {
                d.hide();
            }
        }

        function q(p) {
            if (k) {
                return;
            }
            j.scrollByX(-s, true);
            k = true;
            setTimeout(function() { k = false; }, 850);
        }

        function o(p) {
            if (k) {
                return;
            }
            j.scrollByX(s, true);
            k = true;
            setTimeout(function() { k = false; }, 850);
        }
    });
};

var lastPopsel;
jQuery.fn.showPop = function() {
    var a = arguments[0] || {}, b = this;
    b.each(function() {
        var j = $(this), g, d = j.attr("data-url"), h = j.attr("data-title"), f = a.dim || { w: 300, h: 40 }, k = a.clas || "showpop";
        j.click(function() {
            if ((g == null || g.length <= 0) || lastPopsel != j) {
                if (lastPopsel != null && lastPopsel.length) {
                    lastPopsel.removeClass("sel");
                }
                lastPopsel = j;
                $("." + k).remove();
                j.addClass("sel");
                g = c();
            } else {
                j.removeClass("sel");
                g.remove();
                g = null;
                lastPopsel = null;
            }
        });
        $(window).hashchange(function() { $("." + k).remove(); });

        function c() {
            var l = $('<div class="' + k + '"><div class="wrap">' + ((h.length > 0) ? '<div class="tit">' + h + "</div>" : "") + '<div class="container"></div></div><div class="arrow"></div></div>');
            l.css({ width: f.w, top: j.offset().top - f.h + ((h.length > 0) ? -23 : 0), left: (j.offset().left + j.outerWidth() / 2) - f.w / 2 });
            $("body").append(l);
            $(".container", l).html("Cargando...");
            i(l);
            e();
            return l;
        }

        function e() {
            $.ajax({
                type: "GET",
                url: d,
                data: { id: a.id, tipo: a.tipo, showid: a.showid },
                success: function(l) {
                    $(".container", g).html(l);
                    i(g);
                }
            });
        }

        function i(o) {
            var m = $(".container", o).outerHeight(), l = lastPopsel.offset().top - m + ((h.length > 0) ? -23 : 0);
            o.css({ top: l, height: m });
            l -= 30;
            if ($(document).scrollTop() > l) {
                window.scrollTo(0, l);
            }
        }

        $.extend({
            updateShowPop: function() {
                var l = $("." + k);
                if (l.length) {
                    i(l);
                }
            }
        });
    });
};

var Cuevana = function() {
    t = this, t.list = { search: [], serie: [] }, t.actualhash = "", t.hashvars = [], t.ajaxcalls = [], t.totalajaxcalls = 0, t.playing = false, t.lasturl = "", t.lastdropmenu = "", t.poll = null, t.q = $("#q"), t.main = $("#main"), t.sbar = $("#sbar"), t.newAjaxCallId = function() {
        t.totalajaxcalls++;
        t.ajaxcalls.push(t.totalajaxcalls);
        return t.totalajaxcalls;
    };
    t.delAjaxCall = function(p) {
        var o = t.ajaxcalls.indexOf(p);
        if (o != -1) {
            t.ajaxcalls.splice(o, 1);
        }
    };
    window.onbeforeunload = function() {
        if (t.playing) {
            return lg.closemsg_1;
        } else {
            if (t.ajaxcalls.length > 0) {
                return lg.closemsg_2;
            }
        }
    };
    t.setTitle = function(o) { document.title = "Cuevana | " + o; };
    t.qkey = function(r, q) {
        var p = j(r);
        switch (p) {
        case 27:
            r.preventDefault();
            q.value = "";
            t.listSearch("");
            break;
        case 13:
            if ($("#searchlist a.sel").length > 0) {
                window.location = $("#searchlist a.sel").attr("href");
            } else {
                window.location = "#!/buscar/q:" + q.value;
            }
            q.value = "";
            t.listSearch("");
            break;
        case 37:
        case 38:
        case 39:
        case 40:
            break;
        default:
            var o = q.value;
            setTimeout(function() {
                if (q.value == o) {
                    if (o == "") {
                        t.listSearch(o);
                    } else {
                        t.search(o);
                    }
                }
            }, 200);
        }
    };
    t.keyArrow = function(q, p) {
        var o = j(q);
        switch (o) {
        case 38:
            q.preventDefault();
            t.moveList("up", p);
            break;
        case 40:
            q.preventDefault();
            t.moveList("down", p);
            break;
        case 27:
            q.preventDefault();
            break;
        }
    };
    t.search = function(o) {
        var p;
        if (typeof t.list.search[o] != "undefined" && t.list.search[o].status == 2) {
            t.listSearch(o);
        } else {
            if (typeof t.list.search[o] == "undefined" || t.list.search[o].status != 1) {
                $("#searchload").show();
                p = o;
                t.list.search[o] = { status: 1 };
                $.ajax({
                    type: "POST",
                    url: "ajax/search",
                    data: { q: o },
                    dataType: "json",
                    success: function(q) {
                        t.list.search[o].status = 2;
                        if (q.length > 0) {
                            t.list.search[o].data = q;
                            if (p == o) {
                                t.listSearch(o);
                            }
                        } else {
                            t.listSearch("");
                        }
                    },
                    error: function() {
                        t.list.search[o].status = 3;
                        t.listSearch("error");
                    }
                });
            }
        }
    };
    t.listSearch = function(q) {
        $("#searchload").hide();
        var o = $("#searchlist"), w = $("ul", o), p, u = "";
        switch (q) {
        case "error":
            w.html('<li class="more">Ha ocurrido un error. Inténtelo nuevamente.</li>');
            t.slistSize();
            break;
        case "":
            o.hide();
            break;
        default:
            p = t.list.search[q].data || [];
            if (p.length > 0) {
                for (var r = 0; r < p.length; r++) {
                    u += '<li><a href="#!' + p[r].url + '"> 								<span class="img"><img src="http://sc.cuevana.tv/box/' + p[r].id + '.jpg" border="0" height="54" width="40" /></span> 								' + (p[r].playable ? '<div class="play_label_search"><span></span></div>' : "") + '<span class="tit">' + p[r].tit + '</span> 								<span class="year">' + p[r].year + '</span> 								<span class="info">' + p[r].info + "</span> 							</a></li>";
                }
                if (p.length == 5) {
                    u += '<li class="more"><a href="#!/buscar/q:' + q + '">Ver más resultados</a></li>';
                }
                w.html(u);
                t.slistSize();
            } else {
                o.hide();
            }
        }
        $(document).click(function() {
            if (o.is(":visible")) {
                o.hide();
            }
        });
    };
    t.slistSize = function() {
        var p = $("#searchbox"), o = p.offset();
        $("#searchlist").css({ left: o.left, top: o.top + p.height() + 1 }).show();
    };
    t.moveList = function(y, w) {
        var q = $("#" + w);
        if (q.is(":visible")) {
            var u = $("li", q).not(".sample, .col"), o = u.length, v = $("a", u).index($("a.sel", u));
            switch (y) {
            case "up":
                if (v > 0) {
                    v--;
                }
                break;
            case "down":
                if (v < (o - 1) || (v == 4 && o == 5)) {
                    v++;
                }
                break;
            }
            $("a.sel", u).removeClass("sel");
            var r = $("a", $("li", q).not(".sample, .col").eq(v));
            r.addClass("sel");
            if (w == "serielist") {
                $("#serielist").data("jsp").scrollToElement(r);
            }
        }
    };
    t.skey = function(q, p) {
        var o = j(q);
        switch (o) {
        case 27:
            q.preventDefault();
            p.value = "";
            t.listSerie("");
            break;
        case 13:
            if ($("#serielist a.sel").length > 0) {
                window.location = $("a.sel", $("#serielist")).attr("href");
            }
            break;
        case 37:
        case 38:
        case 39:
        case 40:
            break;
        default:
            t.listSerie(p.value);
        }
    };
    t.listSerie = function(r, C) {
        if (C) {
            t.list.serie = C;
        }
        var F = $("#serielist"), w = t.list.serie, p = w.length, D = $(".sample", F), E = ["tit", "duracion", "temporadas", "episodios", "indexado"];
        if (F.children(".jspContainer").length) {
            var B = F.data("jsp");
            F = F.children(".jspContainer").children(".jspPane");
        }
        $("> li", F).not(".sample").remove();
        if (p > 0) {
            var v = p, y = p;
            do {
                var z = y - v;
                if (r == "" || e(b(w[z].tit)).match(new RegExp("\\b" + r, "ig"))) {
                    var A = D.clone().removeClass("sample");
                    F.append(A);
                    for (var u in E) {
                        $("." + E[u], A).html(w[z][E[u]]);
                    }
                    $("a", A).attr("href", w[z].url);
                }
            } while (--v);
        }
        if (r != "") {
            $("a", $("> li", F).not(".sample").eq(0)).addClass("sel");
        }
        if (typeof B != "object") {
            F.jScrollPane();
            B = F.data("jsp");
        } else {
            B.reinitialise();
            B.scrollTo(0, 0);
        }
    };
    t.minLabel = function(p, w) {
        var v = p.length;
        if (v <= 0) {
            return false;
        } else {
            if (v > 1) {
                var u = "";
                $(w).html(p[0].nombre + " y ");
                var o = v - 1;
                var r = "";
                for (i = 1; i < v; i++) {
                    r += "<li>" + p[i].nombre + "</li>";
                }
                if (!$("#label").length) {
                    $('<div id="label"><div class="arrow"></div><ul class="info"></ul></div>').appendTo("body");
                }
                var q = $("#label");
                $('<span class="minlabel"><a href="#" onclick="return false">' + o + " más</a></span>").appendTo(w).hover(function() {
                    var y = $(this), z = y.offset();
                    $(".info", q).html(r);
                    q.css({ top: z.top + y.outerHeight(), left: z.left }).show();
                }, function() { q.hide(); });
            } else {
                $(w).html(p[0].nombre);
            }
        }
    };
    t.voteList = function(p, r, o) {
        var q = t.newAjaxCallId();
        $.ajax({
            url: "ajax/lista_vote",
            type: "POST",
            data: { act: o, id: r },
            dataType: "json",
            success: function(u) {
                if (u != null && l(u.score)) {
                    var v = $(".puntaje", $(p).parent());
                    v.html(d(parseInt(v.html().replace(/\./g, "")) + parseInt(u.score)));
                }
            },
            complete: function() { t.delAjaxCall(q); }
        });
    };
    t.serializeHash = function(r) {
        if (r == null) {
            r = t.getHash();
        }
        if ($.browser.mozilla && r.indexOf("/url:") > 0) {
            var q = r.substring(0, r.indexOf("/url:") + 5);
            var o = r.substring(r.indexOf("/url:") + 5, r.indexOf("/def:"));
            var w = r.substring(r.indexOf("/def:"), r.length);
            r = q + encodeURIComponent(o) + w;
        }
        var u = r.split("/"), p = u.length, v = "";
        t.hashvars = [];
        if (p > 1) {
            var v = "?";
            for (i = 1; i < p; i++) {
                temphash = u[i].split(":");
                v += "&" + temphash[0];
                if (temphash.length > 1) {
                    v += "=" + temphash[1];
                }
                t.hashvars.push({ key: temphash[0].toLowerCase(), val: ((temphash.length > 1) ? temphash[1].toLowerCase() : null) });
            }
        }
        t.actualhash = u[0].toLowerCase();
        return u[0] + v;
    };
    t.getHash = function() { return window.location.hash.replace(/^#!?\/?/, ""); };
    t.ismain = "", t.mainajax = {}, t.getmain = function(q) {
        if (t.ismain.length > 0) {
            t.mainajax.abort();
        }
        t.ismain = q;
        var o = function(r, u) { t.renderPage(r, u); }, p = 300;
        if (t.isCached(q, p, o)) {
            return;
        }
        t.loader(true);
        t.mainajax = $.ajax({
            url: "web/" + q,
            success: function(r) {
                if (t.ismain == q) {
                    t.loader();
                    t.saveCache(q, r);
                    t.renderPage(q, r);
                    window.scrollTo(0, 0);
                    t.ismain = "";
                }
            },
            error: function(r, v, u) { t.getmain("error404"); }
        });
    };
    t.renderPage = function(o, p) {
        t.tab(o);
        t.main.html(p);
        if (window._gaq) {
            _gaq.push(["_trackPageview", o]);
        }
        $("#labeltop").remove();
    };
    t.load = function(o, u, r, p, q) {
        u = (typeof u == "object") ? $(u) : $("#" + u);
        var v = function(w, y) { u.html(y); };
        if (isCached(o, r, v)) {
            p = (p == null) ? "GET" : p;
        }
        $.ajax({
            url: o,
            type: p,
            data: q,
            success: function(w) {
                t.saveCache(o, w);
                v(o, w);
            },
            error: function(w, z, y) { t.ajaxError(true, z); }
        });
    };
    t.saveCache = function(p, o) { sessionStorage.setItem(p, JSON.stringify({ time: new Date().getTime().toString(), value: a(o) })); };
    t.isCached = function(o, q, r) {
        if (q == null || q <= 0) {
            return false;
        }
        if (sessionStorage != null) {
            if (sessionStorage.getItem(o) != null) {
                var p = $.parseJSON(sessionStorage.getItem(o));
                if (t.cacheTime(parseInt(p.time), q)) {
                    if (typeof r == "function") {
                        r(o, p.value);
                    }
                    return true;
                } else {
                    sessionStorage.removeItem(o);
                }
            }
        }
        return false;
    };
    t.cacheTime = function(p, q) {
        var o = new Date().getTime();
        if ((o - p) > q) {
            return false;
        }
        return true;
    };
    t.tab = function(o) {
        var p = 0, r = $("#mlist"), q = $("li a", r), o = o.replace(/\?(.*)/i, "");
        switch (o) {
        case "series":
            p = 1;
            break;
        case "peliculas":
            p = 2;
            break;
        case "cortos":
            p = 3;
            break;
        case "noticias":
            p = 4;
            break;
        case "usuarios":
        case "listas":
            p = 5;
            break;
        case "foros":
            p = 6;
            break;
        default:
            p = 0;
        }
        if (!q.eq(p).hasClass("sel")) {
            $("#menu").tabs({ main: true, sel: p });
        }
    };
    t.loader = function(p) {
        var o = $("#loader");
        if (p) {
            o.show();
        } else {
            o.hide();
        }
    };
    t.ajaxError = function(p, o) {
        var u = $("#error");
        if (u.length) {
            var r = $("#error_bg"), q = m();
            u.css(lft, (q / 2) - ($("#error").width() / 2));
            $("#error_refresh").focus();
            if (p) {
                u.fadeOut(200, function() { r.fadeOut(200); });
            } else {
                $(document).bind(($.browser.opera ? "keypress" : "keydown"), function(w) {
                    var v = w.keyCode ? w.keyCode : w.which;
                    if (v == 27) {
                        u.fadeOut(200, function() { r.fadeOut(200); });
                    }
                });
                if (!r.length) {
                    $("body").append("<div id='error_bg'></div>");
                    r = $("#error_bg");
                }
                r.css("opacity", 0.5).fadeIn(200, function() { u.fadeIn(200); });
                this.loader.hide();
                $(".tit", u).text(lg.error + ": " + o);
                if (o == "error") {
                    $(".txt", u).text(lg.ajaxerror_1);
                } else {
                    $(".txt", u).text(lg.ajaxerror_2);
                }
            }
        }
    };
    t.insertSpoiler = function() {
        var r = $("textarea"), q = r.getSelection().text;
        if (q.length > 0) {
            var v = "[spoiler]" + q.replace(/\[\/?spoiler\]/gi, "") + "[/spoiler]";
            r.replaceSelection(v);
            r[0].selectionStart = r[0].selectionEnd = r.val().indexOf(v) + v.length;
        } else {
            var v = "Inserta el texto aquí";
            var o = r.insertAtCaret("[spoiler]" + v + "[/spoiler]");
            var u = r[0].selectionStart, p = u - 10;
            r[0].selectionStart = p - v.length;
            r[0].selectionEnd = p;
        }
        r.focus();
    };
    t.listRecientes = function(o, w, r, u, p) {
        if (o == "nologin") {
            w.append('<div class="nologin">' + u + "</div>");
            return;
        }
        ln = o.length, s = $(".sample", w), cl = $("ul", w), tipo = r ? "serie" : "pelicula";
        for (var q = 0; q < ln; q++) {
            if (q % 2 == 0 && q > 0) {
                cl.append('<div class="clear"></div><div class="sep"></div>');
            }
            var v = s.clone().removeClass("sample").show();
            cl.append(v);
            if (q % 2 == 0) {
                v.addClass("impar");
            }
            $(".rate span", v).css("width", Math.round(o[q].rate * 100 / 5) + "%");
            $(".tit a", v).html(o[q].tit).attr("href", o[q].url);
            $(".fecha", v).html(o[q].fecha);
            if (r) {
                $(".ano", v).html(o[q].serie);
            } else {
                $(".ano", v).html(o[q].ano);
            }
            $(".puntuar", v).rate({ defecto: o[q].puntuado, data: { id: o[q].id, tipo: tipo }, label: p });
            if (tipo == "serie") {
                if (o[q].next != "") {
                    $("a.next", v).attr("href", o[q].next);
                } else {
                    $("a.next", v).remove();
                }
            } else {
                t.setactButton($("a.rec", v), parseInt(o[q].rec), { tipo: tipo, id: o[q].id });
            }
        }
        cl.append('<div class="clear"></div>');
    };
    t.setactButton = function(o, q, p) {
        if (typeof p != "object") {
            p = {};
        }
        o.click(function() {
            t.selactButton(o, p);
            return false;
        });
        if (q) {
            o.addClass("sel");
            $(".name", o).html(o.attr("data-sel"));
        }
    };
    t.selactButton = function(o, u) {
        var q = $(".num", o), p = $(".name", o);
        if (o.hasClass("sel")) {
            o.removeClass("sel");
            u.act = "del";
            if (q.length) {
                q.html(parseInt(q.html()) - 1);
            }
            if (p.length) {
                p.html(o.attr("data-nosel"));
            }
        } else {
            o.addClass("sel");
            u.act = "add";
            if (q.length) {
                q.html(parseInt(q.html()) + 1);
            }
            if (p.length) {
                p.html(o.attr("data-sel"));
            }
        }
        var r = t.newAjaxCallId();
        $.ajax({ type: "POST", url: o.attr("data-url"), data: u, error: function(v, y, w) { t.ajaxError(true, y); }, complete: function() { t.delAjaxCall(r); } });
    };
    t.submitForm = function(r, v, p) {
        r = $(r);
        $(".errormsg", r).hide();
        if (p != null && p.length > 0) {
            if (!t.noEmpty(r, p)) {
                return false;
            }
        }
        var u = $(".boton", r), o = $(".load", r);
        u.attr("disabled", "disabled");
        o.show();
        var q = t.newAjaxCallId();
        $.ajax({
            type: "POST",
            url: r.attr("action"),
            data: r.serialize(),
            dataType: "json",
            success: function(w) {
                if (typeof v == "function") {
                    v(w);
                }
            },
            error: function(w, z, y) { t.ajaxError(true, z); },
            complete: function() {
                t.delAjaxCall(q);
                o.hide();
                u.removeAttr("disabled");
            }
        });
    };
    t.noEmpty = function(q, r) {
        for (var o in r) {
            var p = $('input[name="' + r[o] + '"]');
            if (p.length > 0) {
                if (p.val().length == 0) {
                    return false;
                }
            } else {
                p = $('textarea[name="' + r[o] + '"]');
                if (p.length > 0) {
                    if (p.val().length == 0) {
                        return false;
                    }
                }
            }
        }
        return true;
    };
    t.selAvatar = function(o, p) {
        $(".grid_avatars a.sel").removeClass("sel");
        o = $(o);
        o.addClass("sel");
        $("#avatar_id").val(o.attr("data-id"));
    };
    t.dropMenu = function(p, o) {
        o = $(o);
        var q = p.attr("id");
        if (q != t.lastdropmenu && t.lastdropmenu != 0) {
            $("#" + t.lastdropmenu).slideUp("fast");
            o.parent().removeClass("open");
        }
        o.addClass("open");
        p.css({ left: o.offset().left, top: o.offset().top + o.outerHeight() }).slideDown("fast", function() { t.lastdropmenu = q; });
        setTimeout(function() {
            $(document).bind("click.menu_drop", function() {
                if (p.height() > 1) {
                    p.slideUp("fast", function() { t.lastdropmenu = 0; });
                    o.removeClass("open");
                    $(this).unbind("click.menu_drop");
                }
            });
        }, 10);
    };
    t.loadSkin = function(p) {
        if (p == null) {
            var o = h("skin");
            if (o != null && o != "undefined") {
                p = o;
            } else {
                return;
            }
        }
        switch (p) {
        case "light":
        case "dark":
        case "blue":
        case "yellow":
        case "red":
        case "green":
        case "orange":
        case "purple":
            g("skin", p, 30);
            $("head").append("<link rel='stylesheet' type='text/css' href='http://sc.cuevana.tv/new/css/skin_" + p + ".css' />");
            break;
        }
    };
    t.updateActivity = function(p) {
        if (typeof p == "object") {
            var o = $("#m_userbox .log");
            if (p.tot_num > 0) {
                $(".nicon", o).show().children().html(p.tot_num);
            } else {
                $(".nicon", o).hide();
            }
            if (p.msg_num > 0) {
                $("#menu_userbox .msg .num").show().html(p.msg_num);
            } else {
                $("#menu_userbox .msg .num").hide();
            }
            if (p.act_num > 0) {
                $("#menu_userbox .act .num").show().html(p.act_num);
            } else {
                $("#menu_userbox .act .num").hide();
            }
        }
    };
    t.showTrailer = function(p, o) {
        $("#trailersmenu a.sel").removeClass("sel");
        $(o).addClass("sel");
        $("#trailerscont h2").html($(o).text());
        $(".trailer_block").html('<iframe width="510" height="286" src="http://www.youtube.com/embed/' + p + '" frameborder="0" allowfullscreen></iframe>');
    };
    t.setListFrame = function(o, z, y, p) {
        var r = $("#islista"), q = $(".titbar", r);
        r.show();
        $(".tit a", q).html(p.nombre).attr("href", "#!/listas/" + o).addClass(p.priv);
        $(".by a", q).html(p.usuario).attr("href", "#!/usuarios/" + p.usuario);
        $(".users", q).html(d(p.users) + " suscrito" + (p.users != 1 ? "s" : ""));
        $("#slidebox").rowbox({ l: y, set: ["tit", "ano", "reparto", "director", "genero", "duracion", "idioma"] });
        $("#slidebox .arrow").click(function() {
            var B = $(this), D = $(".in", B.parent()), A = $(".boxes", D), C = D.data("jsp");
            if (B.hasClass("rig")) {
                if (C.getContentPositionX() >= (A.width() - D.width())) {
                    return;
                }
                C.scrollByX(D.outerWidth() + 10, true);
            } else {
                if (C.getContentPositionX() == 0) {
                    return;
                }
                C.scrollByX(-(D.outerWidth() + 10), true);
            }
        });
        var u = $("#slidebox .in"), v = u.data("jsp"), w = $("#s" + z);
        w.addClass("glow");
        v.scrollToX(w.position().left, true);
    };
    t.init = function() {
        var o = t.getHash();
        o = (o == "") ? "inicio" : o;
        t.getmain(t.serializeHash(o));
        $(window).hashchange(function() {
            var p = t.getHash();
            p = (p == "") ? "inicio" : p;
            t.getmain(t.serializeHash(p));
        });
        t.loadSkin();
        $("#q").unbind("keyup").keyup(function(p) { t.qkey(p, this); }).unbind("keydown").keydown(function(p) {
            if ($.browser.webkit) {
                t.keyArrow(p, "searchlist");
            }
        }).unbind("keypress").keypress(function(p) {
            if (!$.browser.webkit) {
                t.keyArrow(p, "searchlist");
            }
        });
    };

    function e(p) {
        p = p.split("");
        strAccentsOut = [];
        strAccentsLen = p.length;
        var o = "ÀÁàáÒÓòóôöÈÉèéÇçÌÍìíîïÙÚùúüÑñ", q = ["A", "A", "a", "a", "O", "O", "o", "o", "o", "o", "E", "E", "e", "e", "e", "C", "c", "I", "I", "i", "i", "i", "i", "U", "U", "u", "u", "u", "N", "n"];
        for (var r = 0; r < strAccentsLen; r++) {
            if (o.indexOf(p[r]) != -1) {
                strAccentsOut[r] = q[o.indexOf(p[r])];
            } else {
                strAccentsOut[r] = p[r];
            }
        }
        strAccentsOut = strAccentsOut.join("");
        return strAccentsOut;
    }

    function a(o) { return o.replace(/\s\s*$/gm, "").replace(/\t/gi, ""); }

    function b(p) {
        if (!arguments.callee.sRE) {
            var o = ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "$"];
            arguments.callee.sRE = new RegExp("(\\" + o.join("|\\") + ")", "g");
        }
        return p.replace(arguments.callee.sRE, "\\$1");
    }

    function f(r, q) {
        var v = q.offset().top, u = v + q.height(), o = $(r).offset().top, p = o + $(r).height();
        return ((p >= v) && (o <= u));
    }

    function j(o) { return o.keyCode ? o.keyCode : o.which; }

    function m() { return window.innerWidth ? window.innerWidth : document.body.clientWidth; }

    function n() { return window.innerHeight ? window.innerHeight : document.body.clientHeight; }

    function l(o) { return !isNaN(parseFloat(o)) && isFinite(o); }

    function d(p) {
        p += "";
        x = p.split(",");
        x1 = x[0];
        x2 = x.length > 1 ? "." + x[1] : "";
        var o = /(\d+)(\d{3})/;
        while (o.test(x1)) {
            x1 = x1.replace(o, "$1.$2");
        }
        return x1 + x2;
    }

    function g(q, r, u) {
        if (u) {
            var p = new Date();
            p.setTime(p.getTime() + (u * 24 * 60 * 60 * 1000));
            var o = "; expires=" + p.toGMTString();
        } else {
            var o = "";
        }
        document.cookie = q + "=" + r + o + "; path=/";
    }

    function h(p) {
        var r = p + "=";
        var o = document.cookie.split(";");
        for (var q = 0; q < o.length; q++) {
            var u = o[q];
            while (u.charAt(0) == " ") {
                u = u.substring(1, u.length);
            }
            if (u.indexOf(r) == 0) {
                return u.substring(r.length, u.length);
            }
        }
        return null;
    }

    function k(o) { g(o, "", -1); }
};
var c;
$(document).ready(function() {
    c = new Cuevana();
    c.init();
});
(function(a) {
    a.fn.vAlign = function() {
        return this.each(function(e) {
            var b = a(this).height();
            var f = a(this).parent().height();
            var d = Math.ceil((f - b) / 2);
            a(this).css("margin-top", d);
        });
    };
    a.fn.disableSelection = function() { return this.each(function() { a(this).attr("unselectable", "on").css({ "-moz-user-select": "none", "-webkit-user-select": "none", "user-select": "none", "-ms-user-select": "none" }).each(function() { this.onselectstart = function() { return false; }; }); }); };
})(jQuery);